VBA在SAP GUI中打开新会话并在其中执行事务



大家好,

在SAP GUI中打开新会话(假设用户已经登录到SAP)并在新会话中运行事务的VBA代码是什么?

我很感激你的帮助。

这是我使用的模板,你只需要在excel中添加activex按钮,然后你可以在交易之前添加/o,而你正在记录它。但是不要忘记大多数SAP系统都有会话限制,因此我喜欢像大多数人一样使用相同的会话。

mb52 =比;/omb52

Option Explicit
Public sapAuto As Object
Public WithEvents sapGUI As SAPFEWSELib.GuiApplication
Public sapCon As SAPFEWSELib.GuiConnection
Public WithEvents session As SAPFEWSELib.GuiSession
Dim WSHShell
Dim MyDate1 As Integer
Dim datemin As Date
Dim userID, userPassword, pathFolder As String
Private Sub CommandButton1_Click() 
connectSAP
mb52
killSAP
Application.CalculateFullRebuild
End Sub
Sub connectSAP() 'connect to SAP
On Error GoTo connectionError
Shell "C:Program Files (x86)SAPFrontEndSAPguisaplogon.exe", vbNormalFocus
Set WSHShell = CreateObject("WScript.Shell")
Do Until WSHShell.AppActivate("SAP Logon ")
Application.Wait Now + TimeValue("0:00:01")
Loop
Set sapAuto = GetObject("sapgui")
Set sapGUI = sapAuto.GetScriptingEngine
Set sapCon = sapGUI.Children(0)
Set session = sapCon.Children(0)
Exit Sub:
connectionError:
MsgBox ("Connection Error")
End
End Sub

Sub killSAP() ' kill sap connectio
Set sapAuto = Nothing
Set sapGUI = Nothing
Set sapCon = Nothing
Set session = Nothing
End Sub

Sub mb52() 'wrote/paste your script here


End Sub

最新更新