OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to provide focus to a Window (Excel) using Python

  • Thread starter Thread starter python_SAP
  • Start date Start date
P

python_SAP

Guest
I need to activate a window (make it the foreground window and give it the focus to manipulate) via SAP GUI Scripting. I have automated SAP GUI execution with a Python script. For this module SAP GUI does not do the typical file name and location for the file instead it just outputs it into Excel. I want to shift screens from the SAP GUI to the Excel file and just save it to a path and certain name that is it. Then I can use the rest of my script to manipulate the file from the location I save.

I have tried using win32.com client and reviewed a bunch of forums for SAP GUI and Python but nothing shows how the transition of activating is done from SAP GUI to Excel.

All the lines I have inputted after these crash the code not being recognized or so.

Code:
SAP = win32com.client.GetObject('SAPGUI').GetScriptingEngine
print "T-CODE SECTION CLEAR"
session = SAP.FindByID('ses[0]')
print "T-CODE SECTION CLEAR"
xlapp = win32com.client.Dispatch("Excel.Application")


##START IP24 TRANSACTIONS
session.StartTransaction(Transaction="IP24") 
print "T-CODE SECTION CLEAR"

session.findById("wnd[0]/usr/ctxtEQUNR-LOW").text = "fcsmon*"
session.findById("wnd[0]/usr/ctxtIWERK-LOW").text = "2206"
session.findById("wnd[0]").sendVKey (8)

session.findById("wnd[0]/tbar[1]/btn[8]").press()

session.findById("wnd[0]/mbar/menu[0]/menu[5]").select()

session.findById("wnd[1]/tbar[0]/btn[0]").press()

session.findById("wnd[1]/tbar[0]/btn[0]").press()
session.findById("wnd[1]/tbar[0]/btn[0]").press()
<p>I need to activate a window (make it the foreground window and give it the focus to manipulate) via SAP GUI Scripting. I have automated SAP GUI execution with a Python script. For this module SAP GUI does not do the typical file name and location for the file instead it just outputs it into Excel. I want to shift screens from the SAP GUI to the Excel file and just save it to a path and certain name that is it. Then I can use the rest of my script to manipulate the file from the location I save.</p>
<p>I have tried using win32.com client and reviewed a bunch of forums for SAP GUI and Python but nothing shows how the transition of activating is done from SAP GUI to Excel.</p>
<p>All the lines I have inputted after these crash the code not being recognized or so.</p>
<pre><code>SAP = win32com.client.GetObject('SAPGUI').GetScriptingEngine
print "T-CODE SECTION CLEAR"
session = SAP.FindByID('ses[0]')
print "T-CODE SECTION CLEAR"
xlapp = win32com.client.Dispatch("Excel.Application")


##START IP24 TRANSACTIONS
session.StartTransaction(Transaction="IP24")
print "T-CODE SECTION CLEAR"

session.findById("wnd[0]/usr/ctxtEQUNR-LOW").text = "fcsmon*"
session.findById("wnd[0]/usr/ctxtIWERK-LOW").text = "2206"
session.findById("wnd[0]").sendVKey (8)

session.findById("wnd[0]/tbar[1]/btn[8]").press()

session.findById("wnd[0]/mbar/menu[0]/menu[5]").select()

session.findById("wnd[1]/tbar[0]/btn[0]").press()

session.findById("wnd[1]/tbar[0]/btn[0]").press()
session.findById("wnd[1]/tbar[0]/btn[0]").press()
</code></pre>
 
Top