我正在尝试从SAP的FB04 T代码中提取数据,但无法将数据提取为.xlsx格式。 我的代码无法提取数据并显示错误消息,如“无法通过id找到控件。”,请协助我要出错的地方。
Sub Execute()
Dim base As Worksheet
Set base = ActiveWorkbook.Worksheets("Baseline")
If Not IsObject(SAP_applic) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set SAP_applic = SapGuiAuto.GetScriptingEngine
End If
Set Connection = SAP_applic.Children(0)
If Not IsObject(Connection) Then
Set Connection = Application.Children(0)
End If
If Not IsObject(Session) Then
Set Session = Connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject Session, "on"
WScript.ConnectObject Application, "on"
End If
Session.findById("wnd[0]").maximize
Session.findById("wnd[0]/tbar[0]/okcd").Text = "fb04"
Session.findById("wnd[0]").sendVKey 0
Session.findById("wnd[0]/mbar/menu[3]/menu[0]").Select
Session.findById("wnd[0]/usr/ctxtBUKRS-LOW").Text = "us11"
Session.findById("wnd[0]/usr/ctxtBUKRS-HIGH").Text = "us29"
Session.findById("wnd[0]/usr/ctxtPBS_APAX").Text = "2"
Session.findById("wnd[0]/usr/ctxtBLART-LOW").SetFocus
Session.findById("wnd[0]/usr/ctxtBLART-LOW").caretPosition = 0
Session.findById("wnd[0]/usr/btn%_BLART_%_APP_%-VALU_PUSH").press
Session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,0]").Text = "RV"
Session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,1]").Text = "RX"
Session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,2]").Text = "DZ"
Session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,3]").Text = "AB"
Session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,4]").Text = "DA"
Session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,4]").SetFocus
Session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,4]").caretPosition = 2
Session.findById("wnd[1]/tbar[0]/btn[8]").press
Session.findById("wnd[0]/usr/ctxtDATUM-LOW").Text = base.Range("B1")
Session.findById("wnd[0]/usr/ctxtDATUM-HIGH").Text = base.Range("B2")
Session.findById("wnd[0]/tbar[1]/btn[8]").press
Session.findById("wnd[0]/mbar/menu[0]/menu[1]/menu[1]").Select
Session.findById("wnd[1]/usr/radRB_OTHERS").SetFocus
Session.findById("wnd[1]/usr/radRB_OTHERS").Select
Session.findById("wnd[1]/usr/cmbG_LISTBOX").Key = "10"
Session.findById("wnd[1]/tbar[0]/btn[0]").press
Session.findById("wnd[1]/usr/ctxt[0]").Text = "C:\Users\INNICP\Desktop\Baseline
Reporting"
Session.findById("wnd[1]/usr/ctxt[1]").Text = "Baseline Report.XLSX"
Session.findById("wnd[1]/tbar[0]/btn[11]").press
End Sub