on 2019 Dec 11 9:42 AM
HI Gurus,
I have been trying to open my SAP environment by the use of VBA macros.
I need shell command to work the same way it does while executing RUN command.
For example - If I run sapgui<space>servername<space>instance using Run Command window OR
start<sapce>sapgui<space>servername<space>instance in CLI, it works well.
But as soon as I use the following VBA code, i get the runtime error 53 -
Sub macro()
Dim RetVal
RetVal = Shell("sapgui azsaw0830 00", vbNormalFocus)
End Sub
Please suggest a solution.
Thanks in advance !
Request clarification before answering.
Dim SAPApp As SAPFEWSELib.GuiApplication
Dim SAPConnColl As SAPFEWSELib.GuiComponentCollection
Dim SAPConn As SAPFEWSELib.GuiConnection
Dim SAPSessColl As SAPFEWSELib.GuiComponentCollection
Dim session As SAPFEWSELib.Guisession
Dim SAPGuiAuto As Object
zTime = "00:00:02"
SAPLogonEXE = "\SAP\FrontEnd\SAPgui\SAPlogon.exe"
'Confirm SAP System
On Error Resume Next
Set SAPGuiAuto = GetObject("SAPGUI")
If SAPGuiAuto Is Nothing Then
'Launch SAPLogon.exe
If Environ$("ProgramW6432") Then
OutputFilePath = Environ$("PROGRAMFILES(X86)")
Else:
'handle non 64 bit situations.
OutputFilePath = Environ$("PROGRAMFILES")
End If
If Right(OutputFilePath, 1) <> "\" Then
OutputFilePath = OutputFilePath & "\"
End If
OutputFilePath = OutputFilePath & SAPLogonEXE
x = Shell(OutputFilePath, vbNormalFocus)
Application.Wait Now + TimeValue(zTime)
Set SAPGuiAuto = GetObject("SAPGUI")
End If
On Error GoTo 0
Set SAPApp = SAPGuiAuto.GetScriptingEngine
Set SAPConnColl = SAPApp.Connections
'start looping at systems to connect to the correct session
For Each SAPConn In SAPConnColl
If W_Sess = False Then
If SAPConn.Description = "" Or SAPConn.Description = system Then
If SAPConn.DisabledByServer = False Then
Set SAPSessColl = SAPConn.Sessions
For Each session In SAPSessColl
If session.Busy = False Then
If session.Info.Client = clientID Then
W_Sess = True
Exit For
End If
End If
Next session
Else:
End If
End If
End If
If W_Sess = True Then
Exit For
End If
Next SAPConn
If W_Sess = False Then
Set SAPConn = Nothing
Set SAPConn = SAPApp.OpenConnection(system, True, True)
If SAPConn Is Nothing Then
systemString = SAPUILandscape(system)
If systemString <> "" Then
Set SAPConn = SAPApp.OpenConnectionByConnectionString(systemString, True, True)
Application.Wait Now + TimeValue(zTime)
Else:
Exit Function
End If
End If
Stripped out the main sap gui connection code I use in my spreadsheets. Im guessing this is something close to what you are after.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
45 | |
9 | |
9 | |
6 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.