Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50085

Amending various excel files including those in subfolders MACRO

$
0
0
Hi all

I have approx 500 excel files that i need to make the exact same changes to. As an explanation and for arguments sake i have copied the 500 files from a 2012 directory to a new 2013 directory for this year and every file is for a member of staff. It is a fairly simple deleting data and a year change in several cells.

Doing this manually will take days.

I've put the following together with just a simple updating of 3 cells to say "I am amazing". However I need this to run on all subfolders. My 2013 directory is then split into teams which each member of staffs excel document in each of those folders. I dont want to have to rewrite the macro below for each subfolder.

Any ideas how i can do this... and please keep it simple for me to follow as im not an excel whiz.

Code:

Sub AdjustMultipleFiles()
    Dim sFileName As String
    Dim wbLoopBook As Workbook
    Dim wsLoopSheet As Worksheet

    With Application
        .ScreenUpdating = False: .DisplayAlerts = False: .EnableEvents = False
    End With

    '// Change path to suit
    ChDir "C:\Users\Raff\Desktop\Test"
    SubFolders = True
   
    '// ALL Excel 2007 files
    sFileName = Dir("*.*")
 
    Do While sFileName <> ""
        '// Open Workbook x and Set a Workbook variable to it
        Set wbLoopBook = Workbooks.Open(filename:=sFileName, UpdateLinks:=0)
        '// Loop through all worksheets
        For Each wsLoopSheet In wbLoopBook.Worksheets
        '//Update your worksheets here...
       
        Range("A1").Select
        ActiveCell.FormulaR1C1 = "I"
        Range("A2").Select
        ActiveCell.FormulaR1C1 = "Am"
        Range("A3").Select
        ActiveCell.FormulaR1C1 = "Amazing"
       
        Next wsLoopSheet
        '// Close Workbook & Save
        wbLoopBook.Close SaveChanges:=True
        '// Release object variable
        Set wbLoopBook = Nothing
        '//Next File
        sFileName = Dir
        '//End Loop
    Loop

    With Application
        .ScreenUpdating = True: .DisplayAlerts = True: .EnableEvents = True
    End With

End Sub


Viewing all articles
Browse latest Browse all 50085

Trending Articles