VBA to check SAP Purchase Requisition attachments for Service


Board Regular
Jun 13, 2017
Guys, I am struggling with this....

I am trying to check if there are attachments in PR for service, but I can only check if my macro click to open the attachment table. In some cases, when there are not attachments, the SAP crashes because the macro opened the table where wasn't able to open.

Sub attachment()

        session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:00" & x & "/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:3212/cntlGRIDCONTROL/shellcont/shell").currentCellColumn = ""
        session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:00" & x & "/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:3212/cntlGRIDCONTROL/shellcont/shell").selectedRows = "0"
        session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:00" & x & "/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:3212/cntlGRIDCONTROL/shellcont/shell").pressToolbarButton "&MEREQDMS"
            On Error GoTo 1
            'check if attachments are in the "clip" button in the PR, if there are attachments, go to 1
            Set SAP_attach_ini = session.findById("wnd[1]/usr/txtMESSTXT1")

                If SAP_attach_ini Is Nothing Then
                On Error GoTo -1
                On Error GoTo 0
                ThisWorkbook.Sheets("i1").Cells(Z + 1, 7).Value = 1
                GoTo 2
'if there are no attachments, close popup message and open attachment for services in the toolbox "Services for object" button

                session.findById("wnd[0]/titl/shellcont/shell").pressButton "%GOS_TOOLBOX"

'Here, when there are no attachments, SAP crashes because the following code open "attachment list" if there are or not attachments
                session.findById("wnd[0]/shellcont/shell").pressButton "VIEW_ATTA"
                On Error GoTo 3
'check if there are attachments
                Set SAPattachs = session.findById("wnd[1]/usr/cntlGRID1/shellcont/shell")

I need a solution to check if there are attachments in the clip and in "Services for object" button

Some videos you may like

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.


Board Regular
Jun 13, 2017
I need to check if "Attachment List" is enabled or not:

I have tried all I know but nothing so far worked...

Watch MrExcel Video

Forum statistics

Latest member

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...