How can I write SAP GUI SCRIPT for a SAP pop up window

痞子三分冷 提交于 2020-12-15 07:02:42

问题


I would like to have your help in order to find the solution for the following. I would like to extract SAP standard invoices to PDF files. The steps are VF03 - insert billing doc - Menu: Billing Document - Issue output - select the line - print preview - PDF! + and then I have the pop-up window below. In the pop up window I would like to press the 'SAVE button' and then save the file with specific filename, which I have already copied to clipboard.

The code is the following

 SESSION.findById("wnd[0]").maximize
SESSION.findById("wnd[0]/tbar[0]/okcd").Text = "/NVF03"
SESSION.findById("wnd[0]").sendVKey 0
SESSION.findById("wnd[0]/usr/ctxtVBRK-VBELN").Text = invoice ' "1094542982"
SESSION.findById("wnd[0]/usr/ctxtVBRK-VBELN").caretPosition = 10
SESSION.findById("wnd[0]/mbar/menu[0]/menu[11]").Select
SESSION.findById("wnd[1]/usr/tblSAPLVMSGTABCONTROL").getAbsoluteRow(0).Selected = True
SESSION.findById("wnd[1]/tbar[0]/btn[37]").press
SESSION.findById("wnd[0]/tbar[0]/okcd").Text = "PDF!"
SESSION.findById("wnd[0]").sendVKey 0

回答1:


I tried the following code in order to print the document to pdf Any help on this ? Control+P have been pressed in VBA window, not in SAP window as I want.

    Option Explicit
Public SapGui, App, Connection, Session, SapGuiAuto, wshell, wscript, bWindowFound

Sub SAP()
If Not IsObject(App) Then
   Set SapGuiAuto = GetObject("SAPGUI")
   Set App = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
   Set Connection = App.Children(0)
End If
If Not IsObject(Session) Then
   Set Session = Connection.Children(0)
End If
If IsObject(wscript) Then
   wscript.ConnectObject Session, "on"
   wscript.ConnectObject App, "on"
End If

Set wshell = CreateObject("WScript.Shell")

    Do
     bWindowFound = wshell.AppActivate("PDF Preview")
    Loop Until bWindowFound
    bWindowFound = wshell.AppActivate("PDF Preview")
    'MsgBox ("window found")
     wshell.SendKeys "{CAPSLOCK}"
     MsgBox ("ddd")
     bWindowFound = wshell.AppActivate("PDF Preview")
     wshell.SendKeys "^(p)"
End Sub



回答2:


I would try the following:

...
Set wshell = CreateObject("WScript.Shell")

n = 1
do
 bWindowFound = wshell.AppActivate("Save as")
 n = n + 1
 wscript.sleep 1000 
Loop Until bWindowFound or n > 10

if bWindowFound then
   wshell.SendKeys "myDocument.pdf"
   wscript.sleep 200
   wshell.SendKeys "{TAB 3}"
   wscript.sleep 200
   wshell.SendKeys "{ENTER}"
end if

Regards, ScriptMan



来源:https://stackoverflow.com/questions/59847954/how-can-i-write-sap-gui-script-for-a-sap-pop-up-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!