cancel
Showing results for 
Search instead for 
Did you mean: 

How to interact with the very top menu bar using SAP scripting?

0 Kudos

sap-gui-query.jpgHello,

I'm currently working on an automation project where I have to export F.01 report from SAP but I'm not able to interact with the top-most menu bar (which I've highlighted in the attached picture).

The steps of the SAP scripting would be like this:

Step 1: /nf.01

Step 2: Feed in all the necessary data and Click on 'Execute' button

Step 3: Click on 'List' > 'Export' > 'Spreadsheet' > and so on...

Former Member
0 Kudos
Thank you for visiting SAP Community to get answers to your questions. Since this is your first question, I recommend that you familiarize yourself with: https://community.sap.com/resources/questions-and-answers, as the overview provides tips for preparing questions that draw responses from our members.

Should you wish, you can revise your question by selecting Actions, then Edit.

stefan_schnell
Active Contributor

Hello asifahmed09,

I tried it and in my case I can work with the menu without any problems, e.g.

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

But an item like List > Export > Spreadsheet is in my case not available.

Best regards
Stefan

Hello st.schnell,

Thank you for your response.

I tried what you said but I'm facing an issue with that.

When I'm in the VBA window and executing the VBA codes then the top menu options in the SAP are not showing and thus VBA is giving the error 'The control could not be found by id'. And when I move away from the VBA module/window and go to the SAP screen then the top menu options are showing.

I've attached both screenshots for your reference.

Thanks & Regards.

when-running-vba-top-menu-list-bar-is-not-showing.jpg

otherwise-it-is-showing.jpg

stefan_schnell
Active Contributor
0 Kudos

Hello asifahmed09,

sorry for the delayed reply, vacation.

I tried the following code with VBSEdit in debug mode and in Excel VBA in debug mode.

Sub Main()

  Dim SapGuiAuto As Object
  Dim app As SAPFEWSELib.GuiApplication
  Dim connection As SAPFEWSELib.GuiConnection
  Dim session As SAPFEWSELib.GuiSession

  On Error Resume Next
  Set SapGuiAuto = GetObject("SAPGUI")
  On Error GoTo 0
  If Not IsObject(SapGuiAuto) Then
    MsgBox "Can not get SapGuiAuto", vbOKOnly, "Hint"
    Exit Sub
  End If

  On Error Resume Next
  Set app = SapGuiAuto.GetScriptingEngine
  On Error GoTo 0
  If Not IsObject(app) Then
    MsgBox "Can not get application", vbOKOnly, "Hint"
    Exit Sub
  End If

  app.HistoryEnabled = False

  On Error Resume Next
  Set connection = app.Children(0)
  On Error GoTo 0
  If Not IsObject(connection) Then
    MsgBox "Can not get connection", vbOKOnly, "Hint"
    Exit Sub
  End If

  If connection.DisabledByServer = True Then
    MsgBox "Scripting is disabled by server", vbOKOnly, "Hint"
    Exit Sub
  End If

  On Error Resume Next
  Set session = connection.Children(0)
  On Error GoTo 0
  If Not IsObject(session) Then
    MsgBox "Can not get session", vbOKOnly, "Hint"
    Exit Sub
  End If

  If session.Busy = True Then
    MsgBox "Session is busy", vbOKOnly, "Hint"
    Exit Sub
  End If

  If session.Info.IsLowSpeedConnection = True Then
    MsgBox "Connection is low speed", vbOKOnly, "Hint"
    Exit Sub
  End If

session.findById("wnd[0]/tbar[0]/okcd").Text = "/nf.01"
session.findById("wnd[0]").SendVKey 0

session.findById("wnd[0]/tbar[1]/btn[8]").Press
session.findById("wnd[0]").SendVKey 4

session.findById("wnd[0]/tbar[1]/btn[8]").Press
session.findById("wnd[1]/tbar[0]/btn[0]").Press
session.findById("wnd[0]/mbar/menu[0]/menu[1]/menu[2]").Select

  app.HistoryEnabled = True

End Sub
It works perfect in step by step mode,

Menu is visible.

Best regards
Stefan

Accepted Solutions (0)

Answers (1)

Answers (1)

0 Kudos
  • Activate SAP window
  • Send Global Keys ALT+ .... then. Waite stage on "spied element of submenu" then. 2nd Navigate stage
  • Press spied element of submenu filed in AA mode.

Regards,
J Wick

0 Kudos

Hi Jimmy,

Can you please give a sample code for the explanation which you have given.

Thank you.