Excel到SAP GUI
我正在尝试通过ActiveX按钮运行VBA。由于某些原因,下面显示的代码在尝试获取SAPGUI对象时失败。我已经验证了SAP是开放的,并且在我的客户端和SAP系统上启用了脚本。有什么想法会导致失败吗?我会首先对程序进行以下扩展,然后进一步测试:Excel到SAP GUI,excel,vba,sap-gui,Excel,Vba,Sap Gui,我正在尝试通过ActiveX按钮运行VBA。由于某些原因,下面显示的代码在尝试获取SAPGUI对象时失败。我已经验证了SAP是开放的,并且在我的客户端和SAP系统上启用了脚本。有什么想法会导致失败吗?我会首先对程序进行以下扩展,然后进一步测试: Private Sub CommandButton1_Click() On Error GoTo Err_NoSAP If Not IsObject(SAPGuiApp) Then Set SapGuiAuto = Ge
Private Sub CommandButton1_Click()
On Error GoTo Err_NoSAP
If Not IsObject(SAPGuiApp) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set SAPGuiApp = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = SAPGuiApp.Children(0)
End If
If Not IsObject(SAP_session) Then
Set SAP_session = Connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject SAP_session, "on"
WScript.ConnectObject SAPGuiApp, "on"
End If
If (Connection.Children.Count > 1) Then GoTo Err_TooManySAP
Set aw = SAP_session.ActiveWindow()
aw.findById("wnd[0]").maximize
Err_NoSAP:
MsgBox ("You don't have SAP open or " & Chr(13) & _
"scripting has been disabled."), vbInformation, _
"For Information..."
Exit Sub
Err_TooManySAP:
MsgBox ("You must only have one SAP session open. " & Chr(13) & _
"Please close all other open SAP sessions."), vbInformation, _
"For Information..."
Exit Sub
End Sub
关于,ScriptMan在哪里以及如何失败?我删除了
ExcelVBA
标记;它的描述说不要使用它,因为它正在等待删除。我还删除了vbscript
标记,因为您的代码是VBA,它们不是同一种语言,正如car和carrot是相关的,因为它们都以car开头。你能具体解释一下失败是什么意思,它在哪里以及如何做到的吗?谢谢
...
Set aw = SAP_session.ActiveWindow()
aw.findById("wnd[0]").maximize
'---------- new --------------------------------------
Exit Sub
'---------- new --------------------------------------
Err_NoSAP:
MsgBox ("You don't have SAP open or " & Chr(13) & _
"scripting has been disabled."), vbInformation, _
"For Information..."
Exit Sub
Err_TooManySAP:
MsgBox ("You must only have one SAP session open. " & Chr(13) & _
"Please close all other open SAP sessions."), vbInformation, _
"For Information..."
Exit Sub
End Sub