0
我有一個正確運行的VB腳本,但是在電子表格的循環中,它似乎等待當前電子表格的宏運行,然後再打開下一個電子表格並啓動宏。有沒有辦法一次運行它們,而不是說file2不得不等待文件1打開並運行?代碼如下。VBScript在多個電子表格上運行Excel宏
Dim xlApp
Dim xlBook
Dim f
Dim curfile
Dim username
Dim password
' Prompt user for credentials
username = InputBox("Enter your username")
password = InputBox("Enter your password")
Set fso = CreateObject("Scripting.FileSystemObject")
Set xlApp = CreateObject("Excel.Application")
xlApp.DisplayAlerts = False
For f = 1 to 3
Set xlBook = xlApp.Workbooks.Open(fso.GetParentFolderName(WScript.ScriptFullName) & "\full_volume" & f & ".xlsm", 0, True)
' Paste in credentials to current spreadsheet
xlBook.Sheets("Main").Cells(2,5).Value = username
xlBook.Sheets("Main").Cells(3,5).Value = password
xlApp.Application.Visible = True
xlApp.Run "batch_calc"
' Close Excel File
' xlApp.Quit
Set xlBook = Nothing
Next
Set xlApp = Nothing
WScript.Echo f & " Batch Files Finished"
WScript.Quit