cancel
Showing results for 
Search instead for 
Did you mean: 

How to extract with VBA a desired text field in a document flow into Excel?

Former Member
0 Kudos

Hello,

I am trying to write a VBA code where it should verify if the desired text is within the document flow. With this in mind, the doc flow hierarchical position is variable therefore its position changes as more documents are added. My code includes the 'find' button where I type what I am looking for, but I'm not sure how to get the correct verification answer.

The VBA code should simply check if the file, "Credit Memo Req", is within the list. If is it, then the code should populate a cell with True, otherwise it should say False.

SAP Path

TCode: VA03-> Insert Delivery # -> Display Doc flow

Here's the code I've written so far:

Sub Created_in_Reference()

'***************************************************************************
Set SapGuiAuto = GetObject("SAPGUI")  'Get the SAP GUI Scripting object
Set SAPApp = SapGuiAuto.GetScriptingEngine 'Get the currently running SAP GUI
Set SAPCon = SAPApp.Children(0) 'Get the first system that is currently connected
'Set Connection = App.Children(0) 'Get the first session (window) on that connection
Set session = SAPCon.Children(0) 'Get the first session (window) on that connection
'***************************************************************************

lr = Cells(Rows.Count, "A").End(xlUp).Row
For i = 4 To lr

session.findById("wnd[0]").maximize 'maximizes SAP screen
session.findById("wnd[0]/tbar[0]/okcd").Text = "VA03"
session.findById("wnd[0]/tbar[0]/btn[0]").press
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtRV45Z-LFNKD").Text = Cells(i, 1)
session.findById("wnd[0]/usr/ctxtRV45Z-LFNKD").SetFocus
session.findById("wnd[0]/usr/ctxtRV45Z-LFNKD").caretPosition = 10

'Press doc flow button
session.findById("wnd[0]/usr/btnBT_SUCH").press
session.findById("wnd[0]/tbar[1]/btn[5]").press

'Press the credit memo request (CMR) with the find button
session.findById("wnd[0]/usr/shell/shellcont[1]/shell[0]").pressButton "&FIND"
session.findById("wnd[1]/usr/txtLVC_S_SEA-STRING").Text = "Credit Memo Req"
session.findById("wnd[1]/usr/txtLVC_S_SEA-STRING").caretPosition = 15
<< how to paste this back on Cell(i, 2)?>>

If Err.Number <> 1000 Then
Cells(i, 3) = "Could not verify status"
End If
Next i
End Sub

Accepted Solutions (0)

Answers (0)