+ Reply to Thread
Results 1 to 3 of 3

Trying to remove links when save as a new workbook

  1. #1
    Registered User
    Join Date
    08-23-2019
    Location
    Australia
    MS-Off Ver
    Office 365 Business
    Posts
    28

    Trying to remove links when save as a new workbook

    Hi All,

    I'm still struggling along with my Quote spreadsheet. Very much a newbie to VBA, but trying....

    My spreadsheet pulls last row data from a register to fill fields for a new quote (Date, Company, Quote#) it's a bit of a hack using LOOKUP, =LOOKUP(2,1/('[Quote Register.xlsm]Register'!$B:$B<>""),('[Quote Register.xlsm]Register'!$B:$B)) etc. for the three fields.

    I have some code that should break the links when saved as a new workbook.The problem is that the saved workbook still contains all of the links that were in the original file. Does anyone know a way that I can save the file as values only without the links? If a previously saved workbook is opened for changes to the quote, the fields get updated with newer register data.

    My Code: Has a few snippets which are not necessary? eg: Dim fname As String and fname = ActiveWorkbook.Name
    I've been trying to edit existing code on the run and these were part of an old iteration. I did say I was a learner, my day job is flying airplanes ..


    Sub SaveQuote()
    Dim fname As String
    Dim newFile As String
    Dim NewBook As Workbook
    fname = ActiveWorkbook.Name
    ChDir "C:\users\paul\documents\"
    Call break_links(NewBook)
    ActiveWorkbook.SaveAs Filename:="C:\Users\Paul\Documents\Quote" & " " & Range("D11").Value & " " & Range("K9").Value & (".xlsm")
    End Sub



    Sub break_links(ByRef wb As Workbook)
    Dim Links As Variant
    On Error Resume Next
    Links = wb.LinkSources(Type:=xlLinkTypeExcelLinks)
    On Error GoTo 0
    If Not IsEmpty(Links) Then
    For I = 1 To UBound(Links)
    wb.BreakLink _
    Name:=Links(I), _
    Type:=xlLinkTypeExcelLinks
    Next I
    End If
    End Sub

    Best regards...
    Last edited by Kestrel Aviation; 08-15-2020 at 12:15 PM.

  2. #2
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Trying to remove links when save as a new workbook

    I can provide something for you here. I'm not sure how to interpret your other words, but this:
    Quote Originally Posted by Kestrel Aviation View Post
    Hi All,
    Does anyone know a way that I can save the file as values only without the links?
    that task can be accomplished by simply highlighting the required date, copying it to the clipboard and choosing paste special by right clicking your mouse and choosing values only.

    Quote Originally Posted by Kestrel Aviation View Post
    my day job is flying airplanes ..
    what kind of planes do you fly? I talked to a flight instructor at a restaurant in a nearby town last week. he has been teaching for 40 years. and I programmed and produced the binary databases that guide planes from takeoff to landing (commercial and private panes) about 8 years ago. that's extremely complex stuff.

  3. #3
    Registered User
    Join Date
    08-23-2019
    Location
    Australia
    MS-Off Ver
    Office 365 Business
    Posts
    28

    Re: Trying to remove links when save as a new workbook

    The idea is to generate pre populated fields on a workbook called Quote, with Date, Customer and Quote number from the last used row in another workbook called Quote Register. The problem was if the saved quote is later opened the fields get updated with newer data in the Quote Register.

    I was looking for a solution to break the links when the workbook was saved as a new workbook with Date, Customer and Quote number as the new filename.

    I have found the solution by myself, and learned a little more.


    My new code:
    For Save As...

    Sub SaveQuote()
    Dim fname As String
    Dim newFile As String
    Dim NewBook As Workbook
    fname = ActiveWorkbook.Name
    Sheet1.Unprotect Password:="redacted"
    ChDir "C:\users\paul\documents\"
    ActiveWorkbook.SaveAs Filename:="C:\Users\Paul\Documents\Quote" & " " & Range("D11").Value & " " & Range("K9").Value & (".xlsm")
    BreakExternalLinks
    Sheet1.Protect Password:="redacted", DrawingObjects:=False
    End Sub



    To Break Links...

    Sub BreakExternalLinks()
    Dim ExternalLinks As Variant
    Dim wb As Workbook
    Dim x As Long
    Set wb = ActiveWorkbook
    ExternalLinks = wb.LinkSources(Type:=xlLinkTypeExcelLinks)
    For x = 1 To UBound(ExternalLinks)
    wb.BreakLink Name:=ExternalLinks(x), Type:=xlLinkTypeExcelLinks
    Next x
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 08-11-2020, 03:40 AM
  2. [SOLVED] How to find/remove links to another workbook?
    By aquixano in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-06-2019, 09:13 PM
  3. [SOLVED] VBA for Every 15 min workbook will open and save data and close (for external links update
    By rajeshn_in in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-02-2017, 06:52 PM
  4. [SOLVED] Multiple workbooks into one workbook - asked to save or not save each workbook step remove
    By Benji Jeff in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-20-2014, 09:54 PM
  5. How to save a workbook minus the Microsoft Query links
    By bill_s1416 in forum Excel General
    Replies: 1
    Last Post: 06-16-2009, 04:34 PM
  6. remove all save options from just one workbook
    By 2funny4words in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-23-2009, 01:14 PM
  7. Replies: 2
    Last Post: 02-04-2005, 08:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1