on 12-17-2015 7:30 AM
Hi everybody,
I have following issue:
I have to Export invoices as pdfs using Transaction VF31 and scripting.
Because Spooling is not working I have to print the invoice via Cute Pdf Writer.
Everything works fine but the saving works via normal Windows window (see Picture).
Now my question:
How to enter another Name and press enter? I know there is some VBS code and I'm sure there is some VB compontent but I don't know which one.
thank you very much
bw
Michael
Hello Michael,
the following code should work:
Sub SavePDF()
Set WshShell = CreateObject("WScript.Shell")
WshShell.AppActivate "Speichern unter"
Application.Wait Now + TimeValue("0:00:01")
WshShell.SendKeys "%n"
WshShell.SendKeys "C:\Users\Public\Desktop\001.pdf"
WshShell.SendKeys "%s"
Set WshShell = Nothing
End Sub
You can find a discussion about the control of Windows dialogs here and here a contemplation about different methods of SendKeys from VBA.
Let us know your results.
Cheers
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Stefan,
thank you very very much for your quick answer.
I'm almost there:
I start the script from Excel VBA and the "Speicher unter" window is activated but only for one second and than it is jumped back to Excel VBA so that Alt+N , SendKeys "C:\ ..." and Alt+S is done within the VBA Script and not in the Speicher unter window.
Is there any command to active Speicher unter durably?
I also used the sleep command, expand the +TimeValue() to 5 seconds and used F8 to go through the script but nothing worked
thank you very much
br
Michael
Hello Michael,
try instead WshShell.AppActivate the VBA AppActivate sub routine:
Sub SavePDF()
Set WshShell = CreateObject("WScript.Shell")
Application.Wait Now + TimeValue("0:00:01")
AppActivate "Speichern unter"
WshShell.SendKeys "%n"
WshShell.SendKeys "C:\Users\Public\Desktop\001.pdf"
WshShell.SendKeys "%s"
Set WshShell = Nothing
End Sub
Let us know your results.
Cheers
Stefan
Stefan,
i have tried your very simple code to save PDF Document but without success. I have a variable which stores the filename. On executing WshShell.Sendkeys strFilename, the system types in the variable in the vba code itself and not on the activated SAVE AS Dialog Box.
Could you kindly look into this.
thanks
Amit
************************************************************
Set WshShell = CreateObject("WScript.Shell")
Application.Wait Now + TimeValue("0:00:01")
AppActivate "Speichern unter"
WshShell.SendKeys "%n"
WshShell.SendKeys strFilename
WshShell.SendKeys "%s"
Set WshShell = Nothing
************************************************************
Hi everybody,
sorry for not answering sooner.
The code works.
I had the same problem as you --> it's because you must not start the code in the editor but from Excel or that like. If you start the code from the editor, 'AppActivate' activates the Window for one second and jumps back to the editor in order to execute the next line. If you start the code from somewhere else (not in the editor) you won't have such issues
I've improved the code a little bit: (not the codes waits until the window "SaveAs" (Speichern Unter) is opened
Set WshShell = CreateObject("WScript.Shell")
Do
On Error Resume Next
AppActivate "SaveAs"
Loop Until Err.Number = 0
AppActivate "Speichern unter"
WshShell.SendKeys "%n"
WshShell.SendKeys strFilename
WshShell.SendKeys "%s"
I look for a code sending the parts without activating the window (i.e. in the background) but that takes a while
thanks
br
Michael
Hello Amit and Michael,
I described different methods of SendKeys here, but the target was in this case an SAP session window. In your case it is a Windows dialog, so I think you can use in VBA a solution near by this example.
Let us know your results.
Cheers
Stefan
Hi Michael and Stefan,
I'm new to SAP and VBA. I'm currently on a project in which I need to print (generate pdf doc) via CutePDF Writer. I'm able to select Print option in SAP (via script recorder) however after that I received two windows one to select printer and after selecting OK from this window it will ask to select path to Save.
How I should control both these window and select correct options ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.