VBA 检查 PR SAP 附件
VBA to check for PR SAP attachment
我需要 excel 告诉我下面名为 "Attachment List" 的按钮是否可以点击,但我无法获取。下面是我试过的代码 -
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
我设置 "botao" 从图像列表中获取所有 8 个按钮的数据,但是 none 的属性帮助了我。
我需要这样的东西:
attach = botao.CurrentContextMenu.Children.Item(2).isfocused
代码:"botao.CurrentContextMenu.Children.Item(2)" 将我带到 "Attachment List" 按钮,但没有 属性 对我有帮助。
真的需要帮助。
在我的测试中有一个不存在的附件,下面是一条消息。
如果您不是这种情况,您可以应用以下解决方法,例如:
' 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
我通过使用解决了:
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].. .所以,我做了 2 行,每种情况一行。
我需要 excel 告诉我下面名为 "Attachment List" 的按钮是否可以点击,但我无法获取。下面是我试过的代码 -
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
我设置 "botao" 从图像列表中获取所有 8 个按钮的数据,但是 none 的属性帮助了我。
我需要这样的东西:
attach = botao.CurrentContextMenu.Children.Item(2).isfocused
代码:"botao.CurrentContextMenu.Children.Item(2)" 将我带到 "Attachment List" 按钮,但没有 属性 对我有帮助。
真的需要帮助。
在我的测试中有一个不存在的附件,下面是一条消息。
如果您不是这种情况,您可以应用以下解决方法,例如:
' 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
我通过使用解决了:
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].. .所以,我做了 2 行,每种情况一行。