plwhittington
Board Regular
- Joined
- May 10, 2007
- Messages
- 132
I am using a for-next loop in Excel VBA to search and retrieve information from a list. If the search returns anything, the VBA macro works fine- it displays, copies, and pastes the returned information in my Excel Workbook. If it returns nothing, it fails when trying to copy the query results (because there are none).
The line of code it fails on is: session.findById("wnd[0]").sendVKey 45
I would like for it to skip to the NEXT part of the loop if it encounters this error. I have tried 'on error goto NOTFOUND1:' but it doesn't trigger. Thanks for any help!
Below is part of my code:
For RN = 104 To 394
VendName = UCase(Trim(Range("A" & RN)))
On Error GoTo notfnd1:
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/nse16"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtDATABROWSE-TABLENAME").Text = "LFA1"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/txtI3-LOW").Text = VendName & "*"
session.findById("wnd[0]/usr/ctxtI1-LOW").caretPosition = 5
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]").sendVKey 45
session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[4,0]").Select
session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[4,0]").SetFocus
session.findById("wnd[1]").sendVKey 0
Sheets("TempSheet").Select
Range("A1").Select
ActiveSheet.Paste
notfnd1:
Next RN
The line of code it fails on is: session.findById("wnd[0]").sendVKey 45
I would like for it to skip to the NEXT part of the loop if it encounters this error. I have tried 'on error goto NOTFOUND1:' but it doesn't trigger. Thanks for any help!
Below is part of my code:
For RN = 104 To 394
VendName = UCase(Trim(Range("A" & RN)))
On Error GoTo notfnd1:
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/nse16"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtDATABROWSE-TABLENAME").Text = "LFA1"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/txtI3-LOW").Text = VendName & "*"
session.findById("wnd[0]/usr/ctxtI1-LOW").caretPosition = 5
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]").sendVKey 45
session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[4,0]").Select
session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[4,0]").SetFocus
session.findById("wnd[1]").sendVKey 0
Sheets("TempSheet").Select
Range("A1").Select
ActiveSheet.Paste
notfnd1:
Next RN