cancel
Showing results for 
Search instead for 
Did you mean: 

VBA code to save pdf generated document from SAP using 'CutePDF writer'

Former Member
0 Kudos

Dear Community,

I'm currently writing a code to automate process of -
1. Uploading data from excel to SAP

2. Generate and save excel file (report) on specific folder, like desktop

3. Generate PDF report and save to specific folder.

Using script recorder and many useful contents given on this forum, I some how able to complete point 1 & 2. I stuck at point 3, where I'm able to generate PDF document but not able to save it on the desktop.


Below is my challange:-

Once the PDF (PrintPreview) document is generated, I need to select 'Print' button to select 'CutePDF writer' and press 'OK'.
Then the Save As window pop-up in which I need to enter path to save this pdf file.

Below are the snap-shot of screen your reference (these pop-up in these sequence).

session.findById("wnd[0]/tbar[1]/btn[8]").press                          ' <= This line generate PDF document (PrintPreview)

session.findById("wnd[0]/mbar/menu[0]/menu[0]").Select         ' <= after this line Print window open in which I need to select "CutePDF Writer"

Can some one help, how to access last two windows and select options / data I required.
Any help is much appriciated...

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Sagar,

I handle these by a VBScript. Write & save these in notepad and launch them through Shell from VBA right before VBA gets stuck.

1. The script finds the screen based on the "Save As" text.

2. Enter the full directory in the File name text field

3. Click Save

The following code handles another popup, but it does something very similar.


Set Wshell = CreateObject("WScript.Shell")

do

    bWindowFound = Wshell.AppActivate("SAP GUI Security")

    WScript.Sleep 1000

loop Until bWindowFound

bWindowFound = Wshell.AppActivate("SAP GUI Security")

if (bWindowFound) then

    Wshell.Sendkeys "{TAB}"

    Wshell.Sendkeys "{TAB}"

    Wshell.Sendkeys "{ENTER}"

end if