我需要通过BEx Analyzer更新几个Excel工作簿。我有一个调用脚本A和B的主脚本。
脚本A将填写每次在工作簿中刷新数据时弹出的SAP登录窗口。
脚本B将输入所需的日期。
我遇到的问题是代码适用于第一个工作簿。一旦为第二个(第三个,第四个等)工作簿调用ExcelFileRefresh
函数,脚本A就会开始失败。它不会激活SAP Logon窗口,而是将击键发送到另一个窗口,即包含主脚本的文件夹。
奇怪的是,如果我然后通过双击手动运行脚本A,它将正常工作,脚本B会做它的事情......不幸的是我无法自己解决它。
解决此问题的尝试失败的列表:
WScript.Sleep
暂停。SuccessSAPLogon
设置为Nothing
。主要脚本
Filepath1 = "X:\ExcelBook1.xlsm"
Filepath2 = "X:\ExcelBook2.xlsm"
ExcelFileRefresh(Filepath1)
ExcelFileRefresh(Filepath2)
Function ExcelFileRefresh(Var)
Set Excel = CreateObject("Excel.Application")
Set objShell = CreateObject("WScript.Shell")
Excel.Visible = True
Excel.Workbooks.Open("C:\Program Files (x86)\Common Files\SAP Shared\BW\BExAnalyzer.xla")
Excel.Run ("BExAnalyzer.xla!SetStart")
Set Connection = Excel.Run("BExAnalyzer.xla!sapBEXgetConnection")
Excel.Run("BExAnalyzer.xla!sapBEXinitConnection")
Set ExcelBook = Excel.Workbooks.Open(Var, 0, False)
'--- Initiate Scripts ---'
Set objShell = CreateObject("WScript.Shell")
objShell.Run "ScriptA.vbs"
objShell.Run "ScriptB.vbs"
Excel.Application.Run ("MenuRefreshVariables")
Excel.Run "CommandButton1"
Excel.Run "retreiveData"
ExcelBook.Save
Excel.Quit
Set ExcelBook = Nothing
Set Excel = Nothing
Set objShell = Nothing
End Function
SCRIPTA
Set objShell = CreateObject("WScript.Shell")
SuccessSAPLogon = False
Do While SuccessSAPLogon = False
SuccessSAPLogon = objShell.AppActivate("SAP Logon")
Loop
objShell.SendKeys "{TAB 4}"
objShell.SendKeys "{RIGHT}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "myWarehouse"
objShell.SendKeys "{TAB}"
objShell.SendKeys "BW"
objShell.SendKeys "{ENTER 2}"
ScriptB
Set objShell = CreateObject("WScript.Shell")
SuccessVariables = False
Do While SuccessVariables = False
SuccessVariables = objShell.AppActivate("Select Values")
Loop
objShell.SendKeys "{TAB 3}"
objShell.SendKeys "{DOWN}"
objShell.SendKeys "{TAB 14}"
DateA = DateSerial(Year(Date), Month(Date), Day(Date)-3)
objShell.SendKeys DateA
objShell.SendKeys "{ENTER}"