VBA Error when retrieveing data from SAP: Error message "The virtual key is not enabled"

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
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,223,909
Messages
6,175,312
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top