Bulk Change Connected File In Many Excel Workbook

n13design

New Member
Joined
Feb 1, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
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:

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
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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