shell VBA检查是否启用了SAP GUI按钮菜单项

aamkag61  于 2023-06-24  发布在  Shell
关注(0)|答案(2)|浏览(124)

我需要Excel来告诉我,如果下面的按钮称为“附件列表”可供单击或不,但我无法得到它。下面是我尝试的代码:

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

我设置了“botao”来从图像列表中获取所有8个按钮的数据,但是没有一个属性对我有帮助。
我需要这样的东西:

attach = botao.CurrentContextMenu.Children.Item(2).isfocused

代码botao.CurrentContextMenu.Children.Item(2)将我引导到“附件列表”按钮,但是没有任何有价值的属性可以帮助我。
我真的需要这方面的帮助。

sdnqo3pr

sdnqo3pr1#

在我的测试附带一个不存在的附件下面的消息。
如果您的情况并非如此,您可以应用以下解决方法,例如:

' 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
    ...

问候,ScriptMan

55ooxyrt

55ooxyrt2#

我使用以下方法解决:

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

我只是不知道为什么有时代码有时是[...]/ses[0]/wnd[0],有时是[...]ses[0]/wnd[1]...所以,我做了两行,每一个案件。

相关问题