Good afternoon,
I have an existing code that copies all sheets from all workbooks in a folder. I am having trouble adding a code into this loop to break all external links in the paste destination before closing the workbooks that are copied. Can anyone help me out? Some workbooks have multiple sheets some only one. Here is my code below:
I have an existing code that copies all sheets from all workbooks in a folder. I am having trouble adding a code into this loop to break all external links in the paste destination before closing the workbooks that are copied. Can anyone help me out? Some workbooks have multiple sheets some only one. Here is my code below:
VBA Code:
Sub Button2_Click()
Dim directory As String, fileName As String, sheet As Worksheet, total As Integer
Application.ScreenUpdating = False
Application.DisplayAlerts = False
directory = "M:\NCR & Metrics Worksheets\Metrics\Houston Metrics Workbook\Exports For Current Month\Calculation Process\Calculators\"
fileName = Dir(directory & "*.xlsx")
Do While fileName <> ""
Workbooks.Open (directory & fileName)
For Each sheet In Workbooks(fileName).Worksheets
total = Workbooks("Macro Test 2.xlsm").Worksheets.Count
Workbooks(fileName).Worksheets(sheet.Name).Copy _
after:=Workbooks("Macro Test 2.xlsm").Worksheets(total)
Next sheet
‘Need to break links before closing.
Workbooks(fileName).Close
fileName = Dir()
Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub