Reputation: 3
I need Excel to tell me if the button below called "Attachment List" is available to click or not, but I couldn't get it. Below is the code I tried:
Sub teste()
Set SapGuiAuto = GetObject("SAPGUI")
Set SAPApplication = SapGuiAuto.GetScriptingEngine
Set SAPConnection = SAPApplication.Children(0)
Set session = SAPConnection.Children(0)
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/nme53n"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 17
session.findById("wnd[1]/usr/subSUB0:SAPLMEGUI:0003/ctxtMEPO_SELECT-BANFN").Text = "Purchase Requisition"
session.findById("wnd[1]/usr/subSUB0:SAPLMEGUI:0003/ctxtMEPO_SELECT-BANFN").caretPosition = 8
session.findById("wnd[1]").sendVKey 0
session.findById("wnd[0]/titl/shellcont/shell").pressContextButton "%GOS_TOOLBOX"
Set botao = session.findById("/app/con[0]/ses[0]/wnd[0]/titl/shellcont/shell/")
End Sub
I set "botao" to get all the 8 button data from the list on the image, but none of the properties helped me.
I need something like this:
attach = botao.CurrentContextMenu.Children.Item(2).isfocused
The code botao.CurrentContextMenu.Children.Item(2)
leads me to the "Attachment List" button, but no property was valuable to help me.
I REALLY need help with this.
Upvotes: 0
Views: 1165
Reputation: 1625
In my test comes with a non-existent attachment a message below.
If that is not the case with you, you could apply the following workaround, for example:
' The area at left of title is called the GOS container (shellcont).
' It contains a GuiToolbarControl (shell), with one button named %GOS_TOOLBOX,
' which is of type "ButtonAndMenu" (button with a dropdown menu).
' Click the dropdown part of the button.
session.findById("wnd[0]/titl/shellcont/shell").pressContextButton "%GOS_TOOLBOX"
' Press the menu item "Attachment list"
session.findById("wnd[0]/titl/shellcont/shell").selectContextMenuItem "%GOS_VIEW_ATTA"
' A popup (wnd[1]) should open if there are attachments, otherwise none opens.
on error resume next
session.findById("wnd[1]").close
if err.number <> 0 then
msgbox "There are no attachments."
end if
on error goto 0
...
Regards, ScriptMan
Upvotes: 1
Reputation: 3
I solved by using:
session.findById("wnd[0]/titl/shellcont/shell").pressContextButton "%GOS_TOOLBOX"
session.findById("wnd[0]/titl/shellcont/shell").selectContextMenuItem "%GOS_VIEW_ATTA"
Err.Clear
On Error Resume Next
If session.findById("/app/con[0]/ses[0]/wnd[1]").changeable = True Then
err1 = Err.Number
End If
If session.findById("/app/con[0]/ses[1]/wnd[1]").changeable = True Then
err3 = Err.Number
End If
On Error GoTo 0
If err1 = 619 And err3 = 619 Then
Else
session.findById("wnd[0]").sendVKey 3
I just don't know why sometimes the code sometimes is [...]/ses[0]/wnd[0] and sometimes [...]ses[0]/wnd[1]... so, I made 2 rows, one for each case.
Upvotes: 0