I made it ok to automate a SAP transaction data retrieval by using VBA and SAP record and play .vbs script, now I am facing an issue I did not see in the same program in Visual Basic Studio .NET, if SAP Easy Access for my connection of name: LA-6-Prod is already open then Multilogon window appears and breaks my code thus failing the whole thing.
How can I get my code to use the already existing and open connection or open it if it is not open?
It works perfect if LA-6-Prod is not open, but can not tell the end user to make sure no connection windows are open before executing the macro.
Thank you very much
This is my code:
Sub my_sap
Dim SapGui, Applic, connection, session, WSHShell
strconnection = Worksheets("sap_info").Range("A2").Value
Shell "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe", vbNormalFocus
Set WSHShell = CreateObject("WScript.Shell")
Do Until WSHShell.AppActivate("SAP Logon ")
application.Wait Now + TimeValue("0:00:01")
Loop
Set WSHShell = Nothing
Set SapGui = GetObject("SAPGUI")
Set Applic = SapGui.GetScriptingEngine
Set connection = Applic.OpenConnection('LA-6-Prod', True)
Set session = connection.Children(0)
'===============SAP SCRIPTING===========
'Execute SAP stuffs, I put in here what I recorded from sap record and it works OK
'=======================================
Set session = Nothing
connection.CloseSession ("ses[0]")
Set connection = Nothing
Set sap = Nothing
End Sub