簡體   English   中英

VBA 檢查 PR SAP 附件

[英]VBA to check for PR SAP attachment

我需要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)”將我引導至“附件列表”按鈕,但沒有任何屬性對我有幫助。

真的需要這方面的幫助。

在我的測試中帶有一個不存在的附件,下面是一條消息。

如果您不是這種情況,您可以應用以下解決方法,例如:


    ' 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 行,每個案例一個。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM