Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Aug 2002
    Location
    Tillicoultry, Clackmannanshire, Scotland
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    run a macro on a batch of files (Excel 2000 9.0.44

    I have a macro in Excel to strip the column headers in an Excel file then save the file as a CSV or other format, this works well but my question is how can I get this macro to run on a batch of say 300 Excel files automatically without having to start it manually for each file?

    Cheers
    Seoras

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: run a macro on a batch of files (Excel 2000 9.0.44

    If all 300 files are in one folder, and if they are the only workbooks in that folder, it is relatively easy. Say that your macro is called MyMacro and acts on the currently active workbook. It should save the csv file under a name that relates to that of the workbook, not under a generic name like Export.csv.

    Sub ProcessFolder()
    ' Substitute appropriate folder name
    Const strFolder As String = "C:Excel"
    Dim strFile As String

    strFile = Dir(strFolder & "*.xls")
    Do While strFile <> ""
    Workbooks.Open strFolder & strFile
    ' Process workbook; substitute actual macro name
    MyMacro
    ActiveWorkbook.Close SaveChanges:=False
    strFile = Dir
    Loop
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •