Forum Discussion
Excel Time Saver
Hi,
The following code will work for updating multiple files (although not tested for 200, should work in theory). You will need to update the sample line of code (between the chevrons) for the location you want to input and the text entry itself. I would suggest when first running the code, try with maybe just one or two workbooks to make sure it works as needed since changes are saved during the macro, without UNDO option:
Sub Edit_Multiple_Workbooks()
'
' Edit_Multiple_Workbooks Macro
'
'
Application.ScreenUpdating = False
Dim File_Names As Variant
Dim File_count As Integer
Dim Active_File_Name As String
Dim Counter As Integer
File_Names = Application.GetOpenFilename(, , , , True)
Application.DisplayAlerts = False
File_count = UBound(File_Names)
Counter = 1
If Counter < 1 Then
MsgBox ("File not found")
Exit Sub
End If
Do Until Counter > File_count
Active_File_Name = File_Names(Counter)
Workbooks.Open Filename:=Active_File_Name, UpdateLinks:=0
Active_File_Name = ActiveWorkbook.Name
' Your Required Action Goes Between Chevrons >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
' Example:
Sheets(1).Range("A1") = "Sample Entry to Cell A1"
' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Counter = Counter + 1
ActiveWorkbook.Save
ActiveWorkbook.Close
Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True
MsgBox "All Selected Workbooks Updated"
End Sub
Charla74 can you please talk me through how I'd use this piece of code (quite new to excel) and just confirm where exactly I'd need to put the text i require, can we use 'JD' as an example of the text i want to put in
Appreciate your time
- Charla74Mar 05, 2020Iron ContributorOk, first you’ll need to make sure the developer tab is activated in the ribbon; (File > Options > Customize Ribbon > Check the box for Developer).
Now we’ll record a macro to activate the Personal.xlsb; (View tab > Macros drop down menu > Record a Macro). Enter the name of the macro as TEST, select Personal for the workbook (these means the macro is available in Excel rather than a specific workbook), click OK. Now just type TEST in cell A1, enter, now select Stop Recording from the View tab > Macros drop down menu.
Now we’re ready to enter the code; hit CTRL + F11 to open the VBA Editor > from the panel to the left, right click on Personal and from the menu select Insert Module > Paste the code into the panel on the right and click save (or CTRL + S) > Close the editor > hit CTRL + F8 to bring up macros list and you should now see the macro named Edit_Multiple_Workbooks > click it and then Run.
In the code, where you see "Sample Entry to Cell A1" just change this for “JD”......this is currently set to enter in cell A1 [Range(“A1”)].....you will need to update the cell reference here if you need to input elsewhere.- Charla74Mar 05, 2020Iron ContributorOnce you run the macro, the ‘Open’ box allows you to select multiple files by holding CTRL while selecting each one OR select the first one, hold SHIFT click on the last one (be careful there aren’t files in between which you don’t want changed)