0

I have a VB Script which runs correctly, however, inside the loop of spreadsheets, it seems to wait for the macro of the current spreadsheet to run before opening up the next spreadsheet and kicking off that macro. Is there a way to run them all at once instead of say file2 having to wait for file 1 to open and run? The code is below.

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
4

1 回答 1

0

VBScript 不支持并行执行。作为一种解决方法,您可以修改 VBScript,使其将文件名(可能还有凭据)作为参数,然后使用批处理脚本并行启动脚本:

@echo off

setlocal

set /p "username=Enter your username for TBA: "
set /p "password=Enter your password for TBA: "

for /L %%i in (1,1,3) do (
  start "" cscript.exe //NoLogo script.vbs "%~dp0ah_full_volume%%i.xlsm" "%username%" "%password%"
)
于 2013-10-30T23:40:52.907 回答