Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Script for the SAP report - download to excel - problem

Hi all

I know that similar problem had already been discussed but going through the solution presented in
any of that topic I was not able to be successful  (I am beginner in terms of VBA and SAP scripting)

What I would like to do is simply create the SAP script which based on the parameters filled
in in the excel sheet (user form created) will connect to SAP and make the report which I would like to have saved on my local drive as an excel file.
Everything is ok till the moment I would like to save it.  As you know SAP records the macro only till the moment some window pops up (where and under what name you would like to have your report  saved)

Could you please advise  ?

As a screen I attached also point where macro stops (maybe this makes difference)

Thank you in advance for any suggestions.

Below my code.

Private Sub CommandButton1_Click()

Dim MojaData

MojaData = ComboBox2.Value

Dim Companycode

Companycode = ComboBox1.Value

Dim Depreciation_area

Depreciation_area = ComboBox3.Value

If Not IsObject(Application1) Then

Set SapGuiAuto = GetObject("SAPGUI")

Set Application1 = SapGuiAuto.GetScriptingEngine

End If

If Not IsObject(Connection) Then

Set Connection = Application1.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 Application1, "on"

 

End If

Dim sbar As String

sbar = session.findById("wnd[0]/sbar").Text

  

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

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

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

session.findById("wnd[0]/usr/ctxtBUKRS-LOW").Text = Companycode

session.findById("wnd[0]/usr/ctxtSO_ANLKL-LOW").Text = ""

session.findById("wnd[0]/usr/ctxtBERDATUM").Text = MojaData

session.findById("wnd[0]/usr/ctxtBEREICH1").Text = Depreciation_area

session.findById("wnd[0]/usr/ctxtSRTVR").Text = "0003"

             

session.findById("wnd[0]/usr/radSUMMB").SetFocus

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

session.findById("wnd[0]/mbar/menu[0]/menu[1]/menu[1]").Select

??

Former Member

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question