cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Gui Spricting Vba "Application.DisplayAlters = False"

primax12
Explorer
0 Kudos

I'm new to sap spricting. but i like the idea that i can automate tasks in sap using vba.

Unfortunately, I am now encountering a problem that I cannot solve. I would like to save a list from the cm02 query in excel.

Everything works fine up to the point where I want to save the excel file. The excelfile already exists and I have to confrim that I want to overwrite the excisting file. Normally I would suppress this message by setting application.displayAlerts = false at the beginning of the vba code. unfortunately, application is already defined as an object, otherwise I cannot call sap gui. if I set the code application.displayalters = false, I get an error message "Runtime error 424" - object required.

Below you can see me my code. Is there an other option to suppress the question for overwriting excel file?

Unfortunately I have no idea how to solve this problem. I would appreciate your help and suggestions.

Many thanks in advance.

Sub CM02()

Application.DisplayAlerts = False


Dim Application, SapGuiAuto As Object

If Not IsObject(Application) Then
   Set SapGuiAuto = GetObject("SAPGUI")
   Set Application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
   Set Connection = Application.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 Application, "on"
End If


session.findById("wnd[0]").resizeWorkingPane 126, 39, False
session.findById("wnd[0]/tbar[0]/okcd").Text = "/ncm02"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/mbar/menu[0]/menu[4]/menu[0]").Select
session.findById("wnd[1]/usr/ctxtRC65A-PROFIL_ID").Text = "Z13_B-730T"
session.findById("wnd[1]/usr/ctxtRC65A-PROFIL_ID").caretPosition = 10
session.findById("wnd[1]").sendVKey 0
session.findById("wnd[0]/mbar/menu[0]/menu[4]/menu[3]").Select
session.findById("wnd[1]/usr/ctxtRC65A-LISPROF_ID").Text = "ZPP_TEST"
session.findById("wnd[1]/usr/ctxtRC65A-LISPROF_ID").caretPosition = 8
session.findById("wnd[1]").sendVKey 0
session.findById("wnd[0]/usr/txt[35,3]").Text = "*"
session.findById("wnd[0]/usr/txt[35,7]").Text = "1300"
session.findById("wnd[0]/usr/txt[35,7]").SetFocus
session.findById("wnd[0]/usr/txt[35,7]").caretPosition = 4
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[6]").press
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/tbar[0]/btn[0]").press


session.findById("wnd[0]").resizeWorkingPane 128, 39, False
session.findById("wnd[0]/mbar/menu[4]/menu[11]/menu[1]/menu[1]").Select
session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[0,0]").Select
session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[0,0]").SetFocus
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/tbar[0]/btn[0]").press


  
  Windows("Tabelle von Basis (1)").Activate
    ActiveWorkbook.SaveAs Filename:="C:\Users\Cxxxx\Desktop\test.xlsx", _
        FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
    Windows("Tabelle von Basis (1)").Close



End Sub

 

 

Accepted Solutions (0)

Answers (1)

Answers (1)

rspecht
Explorer

There ist no need to call your SAP-Application-object "Application". You can call it ewhatever you want. E.g. "SAPGUI". Or "APP". Than from line 6 on you can change all "Application" to "SAPGUI" or "APP".