0

I saved my script and connected it to VBA, then I want to copy my local SAP GUI data into an external Excel file.

 Sub FOS()
 If Not IsObject(App) Then
 Set SapGuiAuto = GetObject("SAPGUI")
 Set App = SapGuiAuto.GetScriptingEngine
 End If
 ...
 session.findById("wnd[0]").maximize
 session.findById("wnd[0]/tbar[0]/okcd").Text = "S_ALR_87011964"
 ...
 session.findById("wnd[0]/tbar[1]/btn[19]").press
 session.findById("wnd[0]/usr/chkPA_XGBAF").Selected = True
 session.findById("wnd[0]/usr/chkPA_XGBAF").SetFocus
 session.findById("wnd[0]/tbar[1]/btn[8]").press

 End Sub()

I want to automate an extraction and thus copy my data and transfer them to a very specific Excel file thanks to a VBA macro.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
XDSSIOP
  • 91
  • 3
  • 11

1 Answers1

0

When an ALV Grid Control has been selected, you could try the following.

for example:

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

'for the German SAP version
'SAP_Workbook = "Tabelle von ALV (1)"

'for the English SAP version (?)
SAP_Workbook = "Worksheet in ALVXXL01 (1)"

EXCEL_Path = "c:\tmp\"
myWorkbook = "Report.xlsx"

Set xclwbk = Application.Workbooks.Item(SAP_Workbook)

Application.Visible = True
Application.DisplayAlerts = False

xclwbk.SaveAs Filename:=EXCEL_Path & myWorkbook, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

Set xclwbk = Nothing
'Application.Wait (Now + TimeValue("0:00:02"))
session.findById("wnd[0]/tbar[0]/btn[3]").press
Application.DisplayAlerts = True
...
End Sub

Regards, ScriptMan

ScriptMan
  • 1,580
  • 1
  • 9
  • 9