on 03-17-2019 1:28 PM
Hi All,
I am trying to perform SAPGUI scripting , where i want to login to the SAP system with credentials, and i am able to achieve this successfully with following code lines:
Set SapGuiAuto = GetObject("SAPGUI")
Set Application = SapGuiAuto.GetScriptingEngine
Set Connection = Application.openConnection("EC1")
Set session = Connection.Children(0)
session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "410"
session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "XYZ"
session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "Pwd1"
session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"
session.findById("wnd[0]").SendVKey 0
But here the issue which i am facing is once the line Set Connection = Application.openConnection("EQ2") get executed, it open a separate SAP session in foreground, which is a kind of unnecessary window to show to user and also to process any other action in excel i need to click on excel / minimize manually this new SAP session created.
So is there any way to open a SAP session without bringing that to foreground??
Note : i have tried /INPLACE suffix with the SAP SID, but i am not sure will this help or not as it doesn;t open any window only..
Thanks in Advance,
Avinash
Hello Avinash,
try this to minimize your window:
'-Begin-----------------------------------------------------------------
'-Sub Main--------------------------------------------------------------
Sub Main
Set SapGuiAuto = GetObject("SAPGUI")
Set Application = SapGuiAuto.GetScriptingEngine
Set Connection = Application.openConnection("EQ2")
Set Session = Connection.Children(0)
Session.ActiveWindow.Iconify()
Session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "410"
Session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "XYZ"
Session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "Pwd1"
Session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"
Session.findById("wnd[0]").SendVKey 0
End Sub
'-Main------------------------------------------------------------------
Main
'-End-------------------------------------------------------------------
Best regards
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Stefan,
Thanks for the suggestion, it worked for me.
Can you please let me know how can i minimize the sap login pad which is launched from WShell like below:
Set WSHShell = CreateObject("WScript.Shell")
Set proc = WSHShell.Exec("C:\Program Files (x86)\SAP GUI_7.40_P10_LITE (VMware ThinApp)\saplgpad.exe")
While proc.Status = 0
Wend
Each time i execute the above code i can see always sap logon pad visible over the excel. I have tried following code lines to make excel as foreground application, but it's not minimizing the SAP login pad.
If WSHShell.AppActivate("SAP Logon Pad 740") Then
WSHShell.SendKeys "% n"
End If
WSHShell.AppActivate "Microsoft Excel".
Please suggested me the required steps for the above issue,
Thanks in advance,
Avinash
Setting that option doesn't seem to work for me. The logon pad still stays on top until my vba procedure pastes the SAP data to a worksheet. Here's the connection code I'm using:
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 SapGUIAuto = GetObject("SAPGUI")
Set SapGuiApp = SapGUIAuto.GetScriptingEngine
If SapGuiApp.Connections.Count > 0 Then
Set SapGuiConn = SapGuiApp.Children(0)
Set session = SapGuiConn.Children(0)
Else
Set SapGuiConn = SapGuiApp.OpenConnection("ECC Production", True)
Set session = SapGuiConn.Children(0)
session.TestToolMode = 1
'added part to deal with sap status (open/close)
Set log_opt = session.FindById("wnd[1]/usr/radMULTI_LOGON_OPT2", False)
If Not log_opt Is Nothing Then
log_opt.Select
session.FindById("wnd[1]/tbar[0]/btn[0]").Press
End If
End If
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Avinash,
please set in your SAP Logon options the flag at Hide SAP_Logon (Pad) in tray bar.
And if you now open your connection with...
Set WSHShell = CreateObject("WScript.Shell")
WSHShell.Exec("""C:\Program Files (x86)\SAP\FrontEnd\SAPgui\sapgui.exe"" EQ2 20")
... you didn't see the SAPLogon window and it is also not in the taskbar, only in the tray. The parameters are the SID and the system number. You can get your system number e.g. with TAC SE37 and GET_SYSTEM_NUMBER or in the SAP Logon in column Instance No.
Best regards
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.