Break all links VBA

davec8723

New Member
Joined
Jul 29, 2011
Messages
45
Hi,

Does anyone know how to break all links using VBA quickly? I am using Excel 2003.

For some reason this code does not work for me, which I have been finding all over the internet.

Code:
Sub BreakLinks()
    Dim vLinks As Variant
    Dim lLink As Long
 
    ' Define variable as an Excel link type.
    vLinks = ActiveWorkbook.LinkSources(Type:=xlLinkTypeExcelLinks)
    If vLinks = vbNullString Then Exit Sub
 
    ' Break all links in the active workbook.
    For lLink = LBound(vLinks) To UBound(vLinks)
        ActiveWorkbook.BreakLink _
                Name:=vLinks(lLink), _
                Type:=xlLinkTypeExcelLinks
    Next lLink
End Sub

Thank You!







</PRE>
 
Last edited:
Hi,

Could you help me for multi-workbooks?

how can i break all links for multiple workbooks?

thanks

Onur
The code would break links in activeworkbook.
It should work.
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Try code below. Hope it helps.

Code:
Sub DeleteExternalNames()
    Dim objDefinedName As Object
    Dim iCount As Long
    
    '~~> Speeding Up VBA Code
    Call SpeedUp(False)
    
    For Each objDefinedName In ActiveWorkbook.Names
        If InStr(objDefinedName.RefersTo, "[") > 0 Then
            objDefinedName.Delete
            iCount = iCount + 1
        End If
    Next objDefinedName
    
    '~~> Speeding Up VBA Code
    Call SpeedUp(True)
    
    '~~> Report Result
    If iCount = 1 Then
        MsgBox "[1] external named range was removed from this workbook."
    Else
        MsgBox "[" & iCount & "] external named ranges were removed from this workbook."
    End If
End Sub


'#### SpeedUp (False) - Speeds the VBA Code #####
'#### SpeedUp (True) - Slows down the VBA Code ####
Public Function SpeedUp(Optional bSpeed As Boolean = True)
With Application
    .ScreenUpdating = bSpeed 'Prevent screen flickering
    .Calculation = IIf(bSpeed, xlAutomatic, xlCalculationManual) 'Preventing calculation
    .DisplayAlerts = bSpeed 'Turn OFF alerts
    .EnableEvents = bSpeed 'Prevent All Events
End With
End Function
 
Upvote 0
Just had this issue this morning. It turned out that I had some cells subject to Data Validation i.e. I had restricted the value of certain cells to the values in a range. And this range was in another workbook.

Regarding how I tracked down the problem....I took advantage of the fact that an xlsx / xslm file is basically a zip file. So I made a copy of the file, and changed the extension to .zip. I then unzipped the contents and used a text editor to locate the external workbook. Using an xml editor (although a text editor should suffice) I was able to find the worksheet and the range of cells that were problematic.

I then went back to my Excel document and hey presto, I found the data validation was in error.

Hope this helps.
 
Upvote 0

Forum statistics

Threads
1,223,628
Messages
6,173,429
Members
452,514
Latest member
cjkelly15

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top