While running my VBA code it opens all the correct functions, but when it comes to utilizing the export function - the drop down menu isn't available when pressing export button with VBA, while the drop down menu appears when clicking export button with mouse.
Since it's unable to select the context menu items - given the dropdown does not appear- it gives the following error:
Run-time error '619': The control could not be found by id.
Is there a way to have the context menu appear for the export button ?
Sub SAPconn()
Shell "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe", 4
Set WshShell = CreateObject("WScript.Shell")
Do Until WshShell.AppActivate("SAP Logon ")
Application.Wait Now + TimeValue("0:00:01")
Loop 'keeps looping the wait time until SAP is successfully opened
Set WshShell = Nothing
Set SapGuiAuto = GetObject("SAPGUI") 'open SAP
Set app = SapGuiAuto.GetScriptingEngine 'use the VBScripting ability in SAP
Set connection = app.Openconnection("Production", True) 'open the specific SAP connection
Set session = connection.Children(0)
ThisWorkbook.Activate 'ensure we are getting the information from this specific workbook for the next portion of code
With session
.findById("wnd[0]/usr/txtRSYST-BNAME").Text = Range("c2").Formula 'username
.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = Range("c3").Value 'password
.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN" 'language
.findById("wnd[0]").maximize
.findById("wnd[0]").sendVKey 0 'ENTER to log in
end with
On Error GoTo 0
With session
.findById("wnd[0]").maximize
.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").expandNode "Root"
.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").expandNode "0000000007"
.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").expandNode "0000000039"
.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").expandNode "0000000040"
.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").selectedNode = "0000000041"
.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").topNode = "F00007"
.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").doubleClickNode "0000000041"
.findById("wnd[0]/usr/cmbP_ZINPST").key = "F"
.findById("wnd[0]/usr/cmbP_ZINPST").setFocus
.findById("wnd[0]/tbar[1]/btn[8]").press
.findById("wnd[0]").maximize
.findById("wnd[0]").maximize
.findById("wnd[0]/usr/cntlCONT1/shellcont/shell").PressToolbarContextButton ("&MB_EXPORT")
.findById("wnd[0]/usr/cntlCONT1/shellcont/shell").selectContextMenuItem "&XXL"
.findById("wnd[0]").sendVKey 0
End With
End Sub
Exampe of what code does is shown in this video: video
I have enabled scripting in SAP GUI. I have activated trust access to VBA project object model in the excel macros trust settings.