cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to Save documents thru VBA from VF03

Former Member
0 Kudos

Hi,

I am new in scripting VBA. Need help here. I want to download Invoice copies thru VF03 and save it a desktop or any specific folder.Filw should be saved with Invoice name which will be picked up from range as per loop.

Have generated below loop but unable to save further.

Sub Download_Invoices()

'Initiate SAP

If Not IsObject(SapGuiAuto) Then

   Set SapGuiAuto = GetObject("SAPGUI")

   Set sapapplication = SapGuiAuto.GetScriptingEngine

End If

If Not IsObject(Connection) Then

   Set Connection = sapapplication.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

'SAP Initiated

session.findById("wnd[0]").maximize

session.findById("wnd[0]/tbar[0]/okcd").Text = "/nVF03"

session.findById("wnd[0]").sendVKey 0

i = 2

Do While (Cells(i, 1).Value <> "")

session.findById("wnd[0]/usr/ctxtVBRK-VBELN").Text = Cells(i, 1).Value

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 = False

session.findById("wnd[1]/usr/tblSAPLVMSGTABCONTROL").getAbsoluteRow(1).Selected = True

session.findById("wnd[1]/usr/tblSAPLVMSGTABCONTROL/txtNAST-KSCHL[0,1]").SetFocus

session.findById("wnd[1]/usr/tblSAPLVMSGTABCONTROL/txtNAST-KSCHL[0,1]").caretPosition = 0

session.findById("wnd[1]/tbar[0]/btn[37]").press

session.findById("wnd[0]/tbar[0]/okcd").Text = "PDF!"

session.findById("wnd[0]").sendVKey 0

i = i + 1

Loop

End Sub

Accepted Solutions (0)

Answers (1)

Answers (1)

holger_khn
Contributor
0 Kudos

hello.

THis is an MS com Dialog. So there VBA Stopps until SAP send Dorne Event back. As this will not Happen during Script rüstige it stucks.

you Need To Handle Control of Save Dialog Outside of Script Running instance To succeed. There arme many Threads in this Forum deskribier what is Root cause and options how To Schiene your requirements.

Regards

holger