Forum Discussion

CBHJoshD's avatar
CBHJoshD
Copper Contributor
Mar 05, 2020

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

  • Charla74's avatar
    Charla74
    Iron Contributor

    CBHJoshD 

     

    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

     

    • CBHJoshD's avatar
      CBHJoshD
      Copper Contributor

      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

      • Charla74's avatar
        Charla74
        Iron Contributor
        Ok, first you’ll need to make sure the developer tab is activated in the ribbon; (File &gt; Options &gt; Customize Ribbon &gt; Check the box for Developer).
        Now we’ll record a macro to activate the Personal.xlsb; (View tab &gt; Macros drop down menu &gt; 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 &gt; Macros drop down menu.
        Now we’re ready to enter the code; hit CTRL + F11 to open the VBA Editor &gt; from the panel to the left, right click on Personal and from the menu select Insert Module &gt; Paste the code into the panel on the right and click save (or CTRL + S) &gt; Close the editor &gt; hit CTRL + F8 to bring up macros list and you should now see the macro named Edit_Multiple_Workbooks &gt; 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.
  • PascalKTeam's avatar
    PascalKTeam
    Iron Contributor
    Is 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

Resources