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

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

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

  1. Sub teste()
  2. Set SapGuiAuto = GetObject("SAPGUI")
  3. Set SAPApplication = SapGuiAuto.GetScriptingEngine
  4. Set SAPConnection = SAPApplication.Children(0)
  5. Set session = SAPConnection.Children(0)
  6. session.findById("wnd[0]").maximize
  7. session.findById("wnd[0]/tbar[0]/okcd").Text = "/nme53n"
  8. session.findById("wnd[0]").sendVKey 0
  9. session.findById("wnd[0]").sendVKey 17
  10. session.findById("wnd[1]/usr/subSUB0:SAPLMEGUI:0003/ctxtMEPO_SELECT-BANFN").Text = "Purchase Requisition"
  11. session.findById("wnd[1]/usr/subSUB0:SAPLMEGUI:0003/ctxtMEPO_SELECT-BANFN").caretPosition = 8
  12. session.findById("wnd[1]").sendVKey 0
  13. session.findById("wnd[0]/titl/shellcont/shell").pressContextButton "%GOS_TOOLBOX"
  14. Set botao = session.findById("/app/con[0]/ses[0]/wnd[0]/titl/shellcont/shell/")
  15. End Sub

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

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

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

sdnqo3pr

sdnqo3pr1#

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

  1. ' The area at left of title is called the GOS container (shellcont).
  2. ' It contains a GuiToolbarControl (shell), with one button named %GOS_TOOLBOX,
  3. ' which is of type "ButtonAndMenu" (button with a dropdown menu).
  4. ' Click the dropdown part of the button.
  5. session.findById("wnd[0]/titl/shellcont/shell").pressContextButton "%GOS_TOOLBOX"
  6. ' Press the menu item "Attachment list"
  7. session.findById("wnd[0]/titl/shellcont/shell").selectContextMenuItem "%GOS_VIEW_ATTA"
  8. ' A popup (wnd[1]) should open if there are attachments, otherwise none opens.
  9. on error resume next
  10. session.findById("wnd[1]").close
  11. if err.number <> 0 then
  12. msgbox "There are no attachments."
  13. end if
  14. on error goto 0
  15. ...

问候,ScriptMan

展开查看全部
55ooxyrt

55ooxyrt2#

我使用以下方法解决:

  1. session.findById("wnd[0]/titl/shellcont/shell").pressContextButton "%GOS_TOOLBOX"
  2. session.findById("wnd[0]/titl/shellcont/shell").selectContextMenuItem "%GOS_VIEW_ATTA"
  3. Err.Clear
  4. On Error Resume Next
  5. If session.findById("/app/con[0]/ses[0]/wnd[1]").changeable = True Then
  6. err1 = Err.Number
  7. End If
  8. If session.findById("/app/con[0]/ses[1]/wnd[1]").changeable = True Then
  9. err3 = Err.Number
  10. End If
  11. On Error GoTo 0
  12. If err1 = 619 And err3 = 619 Then
  13. Else
  14. session.findById("wnd[0]").sendVKey 3

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

展开查看全部

相关问题