1

everyone, I need to split a excel file which contains multiple worksheets into individual excel files based on the different worksheet names. I found a VBA code which works very well.

However, now I need to create a batch file to run the VBA code automatically, how to reach this functionality? Since I do not have strong code experience,

hope some one would tell me or give a hint. Here is the code:

Sub Splitbook()
Dim xPath As String
xPath = Application.ActiveWorkbook.Path
Application.ScreenUpdating = False
Application.DisplayAlerts = False

For Each xWs In ThisWorkbook.Sheets
    xWs.Copy
    Application.ActiveWorkbook.SaveAs Filename:=xPath & "\" & xWs.Name & ".xlsx"
    Application.ActiveWorkbook.Close False
Next

Application.DisplayAlerts = True
Application.ScreenUpdating = True

End Sub
0m3r
  • 12,286
  • 15
  • 35
  • 71
ChemCat
  • 11
  • 3
  • 1
    Would a batch code that opens this workbook work? Then you could add an "on open" workbook event to fire the macro. Or do you literally want to run the macro directly from the batch file? – BruceWayne Mar 15 '16 at 20:49
  • 1
    I suggest using VBScript for that case. You also could execute the VBScript via your batch file (if you really need the batch file). [How to do](http://stackoverflow.com/questions/10232150/run-excel-macro-from-outside-excel-using-vbscript-from-command-line) – Dirk Reichel Mar 16 '16 at 02:15
  • You can use the built in windows program "task scheduler" to start a file on log on every `x` time – Bloodied Mar 16 '16 at 03:28
  • Thank you a lot! I will think about all the suggestions. – ChemCat Mar 16 '16 at 14:05

0 Answers0