Hello there. I am in a bit of a pickle. I'm trying to write a vba code that allows the user to loop through multpile files in a directory and break all their links.
When doing it by hand breaking links seems to work but with vba some files return errors.
How is that possible
Here's the code :
Thank you
When doing it by hand breaking links seems to work but with vba some files return errors.
How is that possible
Here's the code :
VBA Code:
Sub kill_links()
Dim vLinks As Variant
Dim MyPath As String
Dim Myfile As String
Dim wb As Workbook
Dim ncp As Workbook
Dim ws As Worksheet
Dim rg1 As String
Application.ScreenUpdating = False
Set wb = Workbooks("Scén.xlsx")
rg1 = wb.Sheets("Scén").Range("C6").Value
MyPath = "C:\home\myfiles\"
Myfile = Dir(MyPath & "\*.xl*")
Do While Myfile <> ""
Set ncp = Workbooks.Open(Filename:=MyPath & "\" & Myfile)
Application.DisplayAlerts = False
Application.AskToUpdateLinks = False
ncp.activate
vLinks = ncp.LinkSources(xlLinkTypeExcelLinks)
If Not IsEmpty(vLinks) Then
for i =1 TO Ubound((vLinks)
wb.BreakLink Name:=vLinks(i), Type:=xlLinkTypeExcelLinks
Next
End If
ncp.Close SaveChanges:=True
End If
Myfile = Dir
Loop
Application.ScreenUpdating = True
End Sub