Skip to Content
avatar image
Former Member

Help required to activate saved workbook from SAP while VBA script is running

Dear Community

I'm doing a project in which I need to download excel report from SAP 7.3 and from the downloaded workbook I need to prepare summary report using different calculations. There are more than 200+ items which I need to download and prepare summary reports, guess need to loop through this task.

When I manually saved one excel report it get automatically open and became my active screen, hence I thought its better to do work on my summary task as soon as I saved the report but its not working. I use normal activate workbook option, but it did not locate the workbook. When I manually stop the code then the workbook get open. any Idea why is this happening..... Has anyone worked on same situation before?

Below is my code:

session.findById("wnd[0]").sendVKey 8 'on this line the SaveAs window pop-up

FilePath = "c:\tmp\Sap download file\ExcelReport1.xlsx") 'I run another vb script to locate the saveAs window and enter path and save it

set Wshell = CreateObject("WScript.Shell")

wshell.run """c:\tmp\save_as.vbs """ & FilePath

Application.wait Now + TimeValue("0:00:05")

workbooks("ExcelReport1.xlsx").activate

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Best Answer
    Apr 13, 2016 at 12:16 PM

    Hi Sagar,

    try it as follows:

    . . .

    wshell.run """c:\tmp\save_as.vbs """ & FilePath, 1, false

    . . .


    Regards,

    ScriptMan

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 13, 2016 at 12:01 PM

    You can´t handle SAP SaveAs dialogue from calling Excel Instance.

    VBA code line Need to be executed until next line will be started. As Long as SaveAs dialogue is open VBA code is waiting for Event send back from SAP to Excel.

    Add comment
    10|10000 characters needed characters exceeded

    • You have started an Event to control in one VBA Excel instance.

      This started Action got handled by another code. Caused by this binding the previous code got no Event back that code line is executed.

      If you have a ALV list which you want to download I would suggest to read this complete list into your Excel instance with Initial code.

      Then there is no Need to use SaveAs. And you can do your calculations in same Excel workbook which contain the SAP ALV list extraction code.

      Add an button on sheet, define some fields on sheet as selection criteria for SAP selection Screen. Then you have an comfortable Excel Workbook for extraction of SAP data and perform some calculations after extraction.