0

I want to get the file name from an attachment inside a Purchase Requisition in SAP using VBA.

I have tried already changing the last line for some random numbers bu nothing happened and I can't manage to discover where I can get the file name.

session.findByid("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:3212/cntlGRIDCONTROL/shellcont/shell").pressToolbarButton "&MEREQDMS"

'here my code tells me if there are any attachment in purchase requisition item
doc = session.findByid("wnd[1]/usr/tblSAPLCVOBTCTRL_DOKUMENTE/ctxtDRAW-DOKNR[1,0]").Text

'starts on item line (0)    
n = 0

    Do While doc <> ""

    session.findByid("wnd[1]/usr/tblSAPLCVOBTCTRL_DOKUMENTE/ctxtDRAW-DOKNR[1," & n & "]").SetFocus
    session.findByid("wnd[1]/usr/tblSAPLCVOBTCTRL_DOKUMENTE/ctxtDRAW-DOKNR[1," & n & "]").caretPosition = 5


'opens the attachment page with the documents inside for download
    session.findByid("wnd[1]").sendVKey 2

    Application.AutomationSecurity = msoAutomationSecurityForceDisable
    Application.AutomationSecurity = msoAutomationSecurityByUI


        q = 1
        s = 0

'num_files returns me "PDF" or "XLS".
        num_files = session.findByid("wnd[0]/usr/tabsTAB_MAIN/tabpTSMAIN/ssubSCR_MAIN:SAPLCV110:0102/cntlCTL_FILES1/shellcont/shell/shellcont[1]/shell").getnodetextbypath(q)

...

Here is the file with file name I need VBA tells me ("Escopo Plataforma..."):

DMS attachment

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Fiinguer
  • 3
  • 2

1 Answers1

0

Please try the following.

for example:

...
'num_files returns me "PDF" or "XLS".
num_files = session.findByid("wnd[0]/usr/tabsTAB_MAIN/tabpTSMAIN/ssubSCR_MAIN:SAPLCV110:0102/cntlCTL_FILES1/shellcont/shell/shellcont[1]/shell").getnodetextbypath(q)

myFileName = session.findByid("wnd[0]/usr/tabsTAB_MAIN/tabpTSMAIN/ssubSCR_MAIN:SAPLCV110:0102/cntlCTL_FILES1/shellcont/shell/shellcont[1]/shell").getitemtext(CStr(q),"C          7")

I assume Item Name "C 7" will be different for you. This is how you determine the correct ItemName:

  1. Record a script with the SAP GUI script recorder.
  2. Click with the mouse in the column with the file name.
  3. Leave the cursor there and finish the recording.
  4. Look in the recorded script for the ItemName.

Regards, ScriptMan

ScriptMan
  • 1,580
  • 1
  • 9
  • 9