2019 May 31 10:54 AM
Hi All,
Please advice, I am trying to run my VBA script to SAP updating 1 or more transaction. but It complete only one transaction.
Below is my Macro code.
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 On Error GoTo Err_Description SAP_session.FindById("wnd[0]").Maximize
SAP_session.FindById("wnd[0]/tbar[0]/okcd").Text = "ZMMP_ARETURN"
SAP_session.FindById("wnd[0]").sendVKey 0
SAP_session.FindById("wnd[0]/usr/ctxtP_MATNR").Text = Cells(11, 1).Value
SAP_session.FindById("wnd[0]/usr/ctxtP_SERNR").Text = Cells(11, 2).Value
SAP_session.FindById("wnd[0]/usr/ctxtP_LGORT").Text = Cells(11, 3).Value
SAP_session.FindById("wnd[0]/usr/txtP_SGTXT").Text = Cells(11, 4).Value
SAP_session.FindById("wnd[0]/usr/ctxtP_SURR").Text = Cells(11, 5).Value
SAP_session.FindById("wnd[0]/usr/ctxtP_SURR").SetFocus
SAP_session.FindById("wnd[0]/usr/ctxtP_SURR").caretPosition = 4
SAP_session.FindById("wnd[0]").sendVKey 8
Exit Sub Err_Description:
MsgBox ("The program has generated an error;" & Chr(13) & _
"the reason for this error is unknown."), vbInformation, _
"For Information..."
Exit Sub 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 Private Sub Worksheet_SelectionChange(ByVal Target As Range) End Sub