Skip to Content
avatar image
Former Member

SAP vbs script to save multiple Print Preview PDF documents?

Hello,

First time post/question. I'm still very new to vbs, but having an issue creating what I hoped would be an 'easy' one.

Before running the script, I use a select all, then a Print Preview (of sorts), which generates an Adobe PDF inside SAP. I simply want the script to hit ctrl + s, hit enter on the windows Save As window to save it to the default location, then click Next and loop until the Next button cannot be found. Note that each time the Save As window comes up, it is a custom file name already--so I don't need to worry about unique file names.

I'm starting light and using this on a selection of 4 documents. The script runs and is able to save off the first pdf file, but then appears to go the last document and stops (cannot tell if it's running too quickly or what).

I have done a bunch of searching and tried numerous alternate approaches without luck. Commands like Wscript.sleep never seem to work whether or not I do them inside a single vbs or put a command in a 2nd vbs file to reference as they give me 'Object Not Found' errors.

Please, if you have something for me to reference, please link me to it instead of asking me to search. Chances are, I've probably read it already haha.

Any ideas?

Again, I'm still new so if you have pointers, please be as specific as you can. Thanks! (I apologieze, but 'Copy Code' was working very poorly for me.)

If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.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 application, "on"
End If
session.findById("wnd[0]").maximize
Set wshell = CreateObject("WScript.Shell")
Do Until session.findById("wnd[0]/sbar/pane[0]").text = "Function code cannot be selected"
session.findById("wnd[0]/usr/cntlHTML_IFBA_PREVIEW/shellcont/shell").SetFocus
wshell.SendKeys "^s"
wshell.SendKeys "{ENTER}"
session.findById("wnd[0]/tbar[1]/btn[39]").press
Loop
MsgBox "Complete"

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Mar 20, 2017 at 04:30 PM

    Hello Eric,

    welcome in this forum and at SAP GUI Scripting.

    Please take a look at this archived thread, hope this answer your question, otherwise let us know.

    Cheers
    Stefan

    Add comment
    10|10000 characters needed characters exceeded

    • Hello Eric,

      thanks for your reply. I think you reach with your script an excellent result. It is possible that the size of the PDF files are in some cases to big and the loading time of the file exceeds the sleeping time or the network traffic is to high so that the transfer speed is to slow.

      Here an example how to check if the "Save as" dialog exists:

      While Not wshell.AppActivate("Save as")
        WScript.Sleep 250
      Wend<br>

      Is it possible for you to use another scripting language? AutoIt offers a lot of possibilities to control the UI, take a look at it.

      Cheers
      Stefa