1

I have created an Excel VBA Macro to connect to SAP GUI, pull data, etc. Nearly everything works, but I have one problem.

I am using the Transaction CV04N to download some documents from it. My code pastes all required Document names (or numbers) into the multiple selection here:

Image: Multiple Selection

After executing it, we get this list:

Image: DocSelection

Now my code just double clicks the list one-by-one and this opens up:

Image: Display Document

So, in most cases, there is only one PDF file in here, but sometimes there is also a TIFF file in there, which then produces an error, because the program tries to download it as a .pdf.

However I only want the PDF. But my program always just selects the first entry.

So I need a function/routine that reads what is in the first line, if it is not PDF, then take the next one. (there are never 2 PDFs in there, so taking the first PDF that shows up is sufficient)

If I just choose document, that only contain PDFs, then everything runs normal.

My current code looks like this (starts from the window shown in last picture)

For j = 0 To k - 1

On Error Resume Next

FileName = XYZ
SaveName = DlFolder & FileName
Session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").currentCellRow = j
Session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").doubleClickCurrentCell

Set Tree = Session.findById("wnd[0]/usr/tabsTAB_MAIN/tabpTSMAIN/ssubSCR_MAIN:SAPLCV110:0102/cntlCTL_FILES1/shellcont/shell/shellcont[1]/shell")

Tree.selectNode "          1"
Tree.nodeContextMenu "          1"
Tree.selectContextMenuItem "CF_EXP_COPY"

'It has selected the "copy to" in context menu, now just saves it to Folder saved in "Savename"
Session.findById("wnd[1]/usr/ctxtDRAW-FILEP").Text = SaveName
Session.findById("wnd[1]/tbar[0]/btn[0]").press
'goes to next doc:
Session.findById("wnd[0]/tbar[0]/btn[3]").press

Next

So, if I could get the data from the Table, I could select the one with TIFF, for that I need to read the table.

I have tried

Tree.Text
Tree.Value
Tree.Copy (and then paste in Excel)

But nothing gives me the correct value...

When I select the entry, and press CTRL-C and paste it somewhere it gives me the whole line, so a String with all columns in this entry.

If you have a solution just to get that mentioned String into a Excel Cell, that's fine with me! From there I can set up some routine to make it work.

I hope I made it understandable what I want, if not please feel free to reach out to me!

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Piperjoe
  • 11
  • 3
  • All the methods and properties are documented here: [GuiTree object](https://help.sap.com/docs/search?q=GuiTree&product=sap_gui_for_windows). – Sandra Rossi Feb 06 '23 at 13:44
  • This Function seems promissing: Public Function GetNodeTextByPath( _ ByVal Path As String _ ) As String I just dont have any idea, how to catch the return of it – Piperjoe Feb 06 '23 at 15:15
  • If all else fails, you could try downloading as pdf and if that throws an exception, try downloading the next line (use script recorder to figure out how to select the second line). – SSlinky Feb 06 '23 at 15:32

0 Answers0