I'd like to update a list of excel files in a folder with a new connected file that's used in formulas. I know I can open each file and click Data > Edit Links > Change Source. I could also do a simple find and replace. My problem is I need to update over 1000 files. I can't get the below to work. I'm new to VBA and I've attempted to combine a few scripts I found here. (Post: 1179753, Video: Bulk Change Many Excel Workbook 2366)
The file I need to replace is has a .xls extension and the new file is a .xlsm.
The formula I'm looking to find looks like this:
This is the VBA I'm trying to use.
The file I need to replace is has a .xls extension and the new file is a .xlsm.
The formula I'm looking to find looks like this:
Excel Formula:
=VLOOKUP($D$2,'R:\filefolder\subfolder\filename.xls'!sheetname,13)
Excel Formula:
=VLOOKUP($D$2,'R:\filefolder\subfolder\[filename.xls]sheetname'!$B$16:$AV$2009,35
This is the VBA I'm trying to use.
VBA Code:
Sub ChangeSheetNameAllWorkbooks()
Dim WB As Workbook
Dim X As Long, F As Variant, R As Variant
F = Array("DATABASE1.xls'!", "DATABASE1.xls]")
R = Array("DATABASE1.xlsm'!", "DATABASE1.xlsm]")
For Each Cell In Selection
Set WB = Workbooks.Open(Cell.Value)
On Error Resume Next
For X = LBound(F) To UBound(F)
WB.Worksheets(1).Cells.SpecialCells(xlCellTypeFormulas).Replace F(X), R(X), xlWhole, , True, , False, False
Next
On Error GoTo 0
WB.Close SaveChanges:=True
Next
End Sub