0
votes

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.

enter image description here

enter code here

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
2
Which SAPGUI version do you have?Storax
Where can I see the version of SAPGUI ?Zounds
In the About Box which you find in the SAPLOGON Pad or in any SAPGUI session. You will see a version, build and patch levelStorax
Release 750. File version 7500.2.5.3376., build 1835159, patch level 5. Are the above Ok?Zounds
I was asking because of this hint.Storax

2 Answers

0
votes

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
0
votes

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