簡體   English   中英

Excel至SAP GUI

[英]Excel to SAP GUI

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

我正在嘗試通過ActiveX按鈕運行VBA。 由於某種原因,以下代碼在嘗試獲取SAPGUI對象時失敗。 我已驗證SAP已打開,並且在客戶端和SAP系統上啟用了腳本。 有什么想法會導致失敗?

我將首先對該程序進行以下擴展,然后對其進行進一步測試:

...
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

問候,ScriptMan

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM