0

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

Attachment List Button

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.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Fiinguer
  • 3
  • 2
  • welcome to so! add some context to your post, so that it will be easy to understand, add like what you trying to achieve? where did you stuck? what error you getting ? also please read [mcve] to know how to make perfect answerable question – Dev Jul 31 '19 at 19:33
  • Thanks. Is that better now? – Fiinguer Aug 01 '19 at 12:11
  • yes better than initial one ,but there is still scope to improve – Dev Aug 01 '19 at 12:38

2 Answers2

1

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

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
ScriptMan
  • 1,580
  • 1
  • 9
  • 9
0

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.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Fiinguer
  • 3
  • 2