Forum Discussion
Excel Time Saver
I have about 200 seperate excel files i would like to place a single piece of text in the exact same cell on each file at once, i do not want to have to go through them all seperately and do it.
6 Replies
- Charla74Iron Contributor
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 IntegerFile_Names = Application.GetOpenFilename(, , , , True)
Application.DisplayAlerts = FalseFile_count = UBound(File_Names)
Counter = 1If Counter < 1 Then
MsgBox ("File not found")
Exit Sub
End IfDo 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.CloseLoop
Application.ScreenUpdating = True
Application.DisplayAlerts = TrueMsgBox "All Selected Workbooks Updated"
End Sub
- Charla74Iron 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.
- PascalKTeamIron ContributorIs this a one time activity? In this case I guess doing it manually with copy paste is the best solution as setting up the VBA and testing it also takes some time. If you need to do this on a regular basis, then of course a macro would be the way forward
- CBHJoshDCopper Contributor
PascalKTeam it has to be done every 6 months, its just a very time consuming process