EXCEL: How to break all links before saving

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Michel
Newbie
Posts: 17
Joined: Fri May 20, 2011 2:12 pm
Location: Ottawa

EXCEL: How to break all links before saving

Post by Michel » Wed Jun 08, 2011 6:50 pm

I've open an EXCEL via the following command:

XLOpen>%PathFileName%,0,XLBookHandle

The EXCEL has several links.
What's the best way to BREAK all links and save file as
PathFileName_no_links

Thanx.
... Michel

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Jun 09, 2011 2:09 pm

Just answered this privately so for benefit of everyone else here's some code that will attach to XL and break the links in the active workbook:

Code: Select all

//put this block at top
VBSTART
Dim xlApp 
Dim xlBook 
Sub GetXL 
  Set xlApp = GetObject(,"Excel.Application") 
  Set xlBook = xlApp.ActiveWorkbook 
End Sub

Sub BreakLinks()
  Dim astrLinks
  If Not IsEmpty(xlBook.LinkSources(1)) Then
    For Each Link in xlBook.LinkSources(1)
      xlBook.BreakLink Link, 1
    Next
  End if
End Sub
VBEND

//call these lines to break the links before saving and quitting
VBRun>GetXL
VBRun>BreakLinks
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Michel
Newbie
Posts: 17
Joined: Fri May 20, 2011 2:12 pm
Location: Ottawa

Post by Michel » Thu Jun 09, 2011 2:24 pm

Brilliant-!

Thanx...

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts