Cannot save the SAP export file

Dawid88

New Member
Joined
Mar 30, 2021
Messages
3
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello,
I'm trying to save the excel file generated from SAP. Unfortunatly, I'm not able to save ite directly from SAP. SAP only allows to export the excel. The problem is that my macro doesn't find that generated file. Could you please help me to find solution?


VBA Code:
Function ExportYE3(Groupname As String, Closingdate As Date, CompanyCode As String) As String

ExportYE3 = ExportYE3 & vbNewLine & " - " & Now() & " - ExportYE3 - Start for " & Groupname


On Error GoTo 112

'Start transaction
With Session
.StartTransaction "YE3"


'Input parameters
Session.findById("wnd[0]/usr/txtS_GJAHR-LOW").Text = Year(Closingdate)
Session.findById("wnd[0]/usr/ctxtS_PERIOD-LOW").Text = Month(Closingdate)
Session.findById("wnd[0]/usr/ctxtS_BUKRS-LOW").Text = CompanyCode
Session.findById("wnd[0]/usr/ctxtS_BU-LOW").Text = Groupname
Session.findById("wnd[0]/usr/radRB_EXC").SetFocus
Session.findById("wnd[0]/usr/radRB_EXC").Select

'Launch
Session.findById("wnd[0]").sendVKey 8

'Save - not working!!!
Worksheets(Workbooks.Count).Activate
ActiveWorkbook.SaveAs filename:=ThisWorkbook.Path & "\YE3.XLSX"


Exit Function

I have alredy trieddifferent approaches, but cannot save opened export file:
'Worksheets(Workbooks.Count).SaveAs filename:=ThisWorkbook.Path & "\YE3.XLSX"
'Windows("Sheet1").SaveAs filename:=ThisWorkbook.Path & "\YE3.XLSX"
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
If your macro (which one?) don't find that file then probably it has been opened in a separate excel session: start Task Manager and check if you see one or two "Microsoft Excel" running tasks.
I would suggest that you insert the macro to save such a workbook into your PERSONAL.xlsm; then you personalize your quick access toolbar and insert there an icon to start the Personal.xlsm!MacroXYZ

Bye
 
Upvote 0
Thank you for answer. You are right. Excel after export from SAP opens in the new sesion/instance. I have to share the file with macro with other people so the macro should be saved inside the file. Is there any way to change the instance, save the file, and come back to the first sesion to continue further steps of the macro?
 
Upvote 0
The way the exported file opens is controlled by SAP.
Maybe you should base your automation on saving the sap file (vs opening it with Excel); then your macro will search the saved file, open it and continue the process...

But let's wait for some wiser suggestions

Bye
 
Upvote 0
The way the exported file opens is controlled by SAP.
Maybe you should base your automation on saving the sap file (vs opening it with Excel); then your macro will search the saved file, open it and continue the process...

But let's wait for some wiser suggestions

Bye
I use the approach of saving file directly from SAP in other macros. Unfortunately, this time I'm trying to download the personalized SAP report which has no option to be saved.
 
Upvote 0

Forum statistics

Threads
1,214,821
Messages
6,121,762
Members
449,048
Latest member
excelknuckles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top