cancel
Showing results for 
Search instead for 
Did you mean: 

How to open a SAP session without bringing that to foreground from SAP GUI VB scripting?

avinashd_m
Participant
0 Kudos

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

View Entire Topic
stefan_schnell
Active Contributor

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

avinashd_m
Participant
0 Kudos

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