on 03-12-2019 8:34 AM
Hi everyone,
I have the following situation: I need to export from SAP 750 the invoices from VF02 but i am not able to do it. I wrote the below code, which is straightforward but it is simply not working. The VBA dosen't provide any error and finish the task but here is no output. The line that should open the the save dialog do nothing:
Public Sub ExportInvoices()
'ByVal vStrPathSAP As String
Dim CC, BillingDoc As String
Dim vcounter As Integer
'set condition to start loop until active cell become blank
ThisWorkbook.Activate
Sheets("Sheet1").Select
Range("A1").Select
Do While ActiveCell.Value <> ""
'establish active row
Range("A1").Select
vcounter = ActiveCell.Row
Set xclapp = GetObject(, "Excel.Application")
Set xclwbk = xclapp.ThisWorkbook
Set xclsht = xclwbk.Sheets("Sheet1")
BillingDoc = xclsht.Cells(vcounter, 9).Value
CC = xclsht.Cells(vcounter, 2).Value
Dim App, Connection, session As Object
Set SapGuiAuto = GetObject("SAPGUI")
Set App = SapGuiAuto.GetScriptingEngine
Set Connection = App.Children(0)
Set session = Connection.Children(0)
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/nVF02"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtVBRK-VBELN").Text = BillingDoc
session.findById("wnd[0]/usr/ctxtRV60S-BUKRS").Text = CC
session.findById("wnd[0]/usr/ctxtRV60S-BUKRS").SetFocus
session.findById("wnd[0]/usr/ctxtRV60S-BUKRS").caretPosition = 4
session.findById("wnd[0]/mbar/menu[0]/menu[11]").Select
session.findById("wnd[1]/tbar[0]/btn[37]").press
--->>> nothing happend from here
Set WshShell = CreateObject("WScript.Shell")
WshShell.AppActivate "Print Preview, Document 1 of 1"
'set the focus to the Acrobat control based on ID of the control
session.findById("wnd[0]/usr/cntlHTML_IFBA_PREVIEW/shellcont/shell").SetFocus
WshShell.SendKeys "^+s" 'Open save dialog
WshShell.SendKeys "%n" 'Activate file name field
WshShell.SendKeys "\\Invoices under investigation\" & Excel.Cells(vcounter, "B") & "\" & Excel.Cells(vcounter, "I") & ".pdf" 'Path and file name
WshShell.SendKeys "%s" 'Save the file
'go to next row
ActiveCell.Offset(1, 0).Activate
vcounter = ActiveCell.Row
Loop
End Sub
I have the same solution. did you do it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
101 | |
13 | |
13 | |
11 | |
11 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.