on 2022 Aug 19 1:41 PM
I need to read and copy the text from a SAP GUI pop up window using VBA. I have managed to create a code that navigates through the grid table and clicks on the cell with the document column (see image below):
Then this pop -up window opens and I need to copy the text from it:
Here is the code that runs that I use, but when I get to the line ntxt=ssn.findById("wnd[1]/usr/cnt1CHGTEXT/shellcont/shell").Text the variable comes out blank. Help will be highly appreciated. Thanks.
I am also including the watches VBA window that actually shows the field I need to get to:
Dim sapg As Object: Dim appx As Object
Dim conx As Object: Dim ssn As Object
Dim coll As Collection: Dim mfg As clsMFGdash
Dim rwx As Long: Dim rcn As Long: Dim ntxt As String
'set the current workbook and worksheet
Set wbc = Workbooks(cfile): Set shc = wbc.Sheets("user")
Set sht = wbc.Sheets("data")
'SAP GUI must be up and running, user must be logged in for this code to work
'connecting to SAP GUI
If IsObject(appx) Then
Set sapg = GetObject("SAPGUI")
Set appx = sapg.GetScriptingEngine
End If
If IsObject(conx) Then
Set conx = appx.Children(0)
End If
If IsObject(ssn) Then
Set ssn = conx.Children(0)
End If
'once the dashboard has loaded, select all and change owner
Dim chgOW As String: Dim chgNts As String
'this is the window
chgOW = "wnd[0]/usr/subSUB1:ZOMU0057_SCHED_CHG_DASHBOARD:0101/tabsTAB_CTL_0101/tabpMFG_APPR/ssubSUB2:ZOMU0057_SCHED_CHG_DASHBOARD:0203/cntlS_CTRL203/shellcont/shell"
chgNts = "wnd[1]/usr/cntlCHGTEXT/shellcont/shell"
Set gridMFG = ssn.findById(chgOW)
'Count the total number of rows and visible rows
rcn = ssn.findById(chgOW).RowCount - 1
vcn = ssn.findById(chgOW).visiblerowCount
crr = 0 'first visible row position
rwx = 0 'unused row in the target sheet "data"
'create the new collection that will hold each record
Set coll = New Collection
'loop through all the lines in the dashboard
For x = 0 To rcn
'create the row
Set mfg = New clsMFGdash
'read the current row (x) and save the cell value for each field
mfg.nots = Trim(gridMFG.getCellValue(x, "TEXT"))
If mfg.nots <> "" Then
'set the current cell with the note and click on it
gridMFG.setCurrentCell x, "TEXT"
gridMFG.SetFocus
gridMFG.clickCurrentCell
'read the data from the window
Set gridWND = ssn.findById(chgNts)
ntxt = ssn.findById("wnd[1]/usr/cntlCHGTEXT/shellcont/shell").Text
Set gridWND = Nothing
End If
mfg.appMAD = Trim(gridMFG.getCellValue(x, "ZZAPPR_MAD"))
mfg.mfgOwnr = Trim(gridMFG.getCellValue(x, "ZZMFG_OWN"))
mfg.cmmnts = Trim(gridMFG.getCellValue(x, "ZZCHG_COMMENT"))
mfg.dpX = Trim(gridMFG.getCellValue(x, "LPRIO"))
mfg.ofRep = Trim(gridMFG.getCellValue(x, "ZZREPID"))
mfg.prior = Trim(gridMFG.getCellValue(x, "ZZURGENT"))
mfg.dateToMFG = Trim(gridMFG.getCellValue(x, "TO_MFG_DATE"))
mfg.timeToMFG = Trim(gridMFG.getCellValue(x, "TO_MFG_TIME"))
mfg.submittr = Trim(gridMFG.getCellValue(x, "ZZERNAM"))
mfg.soX = Trim(gridMFG.getCellValue(x, "VBELN"))
mfg.lnX = Trim(gridMFG.getCellValue(x, "POSNR"))
mfg.vendor = Trim(gridMFG.getCellValue(x, "VENDOR_NAME"))
mfg.vpoX = Trim(gridMFG.getCellValue(x, "EBELN"))
mfg.qty = Trim(gridMFG.getCellValue(x, "ZQTY"))
mfg.poDueD = Trim(gridMFG.getCellValue(x, "PO_DUE_DATE"))
mfg.reqPOdueD = Trim(gridMFG.getCellValue(x, "REQ_PO_DUE_DATE"))
mfg.appPOdueD = Trim(gridMFG.getCellValue(x, "APPR_PO_DUE_DATE"))
mfg.reasonC = Trim(gridMFG.getCellValue(x, "ZZREASON_CODE"))
mfg.dateToVendor = Trim(gridMFG.getCellValue(x, "ZZDATE_TO_VNDR"))
mfg.timeToVendor = Trim(gridMFG.getCellValue(x, "ZZTIME_TO_VNDR"))
mfg.dateFromVndr = Trim(gridMFG.getCellValue(x, "ZZDATE_FR_VNDR"))
mfg.timeFromVndr = Trim(gridMFG.getCellValue(x, "ZZTIME_FR_VNDR"))
mfg.chgFrom = Trim(gridMFG.getCellValue(x, "ZTEXT_FROM"))
mfg.chgTo = Trim(gridMFG.getCellValue(x, "ZTEXT_TO"))
mfg.appTxt = Trim(gridMFG.getCellValue(x, "ZZAPPR_TEXT"))
mfg.reqQty = Trim(gridMFG.getCellValue(x, "ZQTY_N"))
mfg.appQty = Trim(gridMFG.getCellValue(x, "ZZAPPR_QTY"))
mfg.description = Trim(gridMFG.getCellValue(x, "ARKTX"))
mfg.spmo = Trim(gridMFG.getCellValue(x, "SPMO"))
mfg.ultCust = Trim(gridMFG.getCellValue(x, "NAME1"))
mfg.leadDays = Trim(gridMFG.getCellValue(x, "ZLDAY"))
mfg.material = Trim(gridMFG.getCellValue(x, "MATNR"))
mfg.spcl = Trim(gridMFG.getCellValue(x, "SPCL"))
mfg.csm = Trim(gridMFG.getCellValue(x, "CSM"))
mfg.csmo = Trim(gridMFG.getCellValue(x, "CSMO"))
mfg.mfgl = Trim(gridMFG.getCellValue(x, "MFGL"))
mfg.ebd = Trim(gridMFG.getCellValue(x, "EBD"))
mfg.chgCurrMAD = Trim(gridMFG.getCellValue(x, "ZZCONF_MAD"))
mfg.chgReqMAD = Trim(gridMFG.getCellValue(x, "ZZCONF_MAD_N"))
mfg.reasonD = Trim(gridMFG.getCellValue(x, "AUGRU"))
'append the row to the collection
coll.Add mfg
'these lines will help scrolldown as we continue tu run through the data
If (x - crr) >= vcn Then
crr = x + 1
gridMFG.firstVisibleRow = crr
vcn = Empty: vcn = ssn.findById(chgOW).visiblerowCount
End If
'vcn = Empty
'vcn = ssn.findById(chgOW).visiblerowCount
Next x
rwx = Empty
Request clarification before answering.
User | Count |
---|---|
60 | |
10 | |
8 | |
8 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.