This is the template I use, you just need to add activex button in excel then you can add /o before your transaction while you are recording it. But Dont forget most SAP system has session limits, thus I prefer using same session like most people.
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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…