Broken Code Importing data from Internet Explorer

bubububub

New Member
Joined
Jul 2, 2010
Messages
18
Hello,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p> </o:p>
This code is designed to enter a search for UPCs at http://www.upcdatabase.com/itemform.asp. Then it copies the url of the search results page and pastes it in excel next to its matching UPC. The end result should be a column of UPC numbers and a column of urls.<o:p></o:p>
<o:p> </o:p>
But every time I run code, I receive the error:<o:p></o:p>
Run-time error '91':<o:p></o:p>
Object variable or With block variable not set<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
When I choose the debug option, this line is highlighted:<o:p></o:p>
doc.all("upc").Value = rngUPC.Text<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
Any ideas to fix my broken code?<o:p></o:p>
<o:p></o:p>
Thanks for your help,<o:p></o:p>
<o:p> </o:p>
Bub
P.S. Thanks, Norie, for helping me thus far.
Rich (BB code):
Rich (BB code):
Rich (BB code):
Sub Test()<o:p></o:p>
Dim IE As Object<o:p></o:p>
Dim doc As Object<o:p></o:p>
Dim frm As Object<o:p></o:p>
Dim rngUPC As Range<o:p></o:p>
<o:p> </o:p>
    Set IE = CreateObject("InternetExplorer.Application")<o:p></o:p>
 <o:p></o:p>
    Set rngUPC = Range("A1")<o:p></o:p>
 <o:p></o:p>
    With IE<o:p></o:p>
 <o:p></o:p>
        While rngUPC.Value <> ""<o:p></o:p>
<o:p> </o:p>
            .Navigate "http://www.upcdatabase.com/itemform.asp"<o:p></o:p>
<o:p> </o:p>
            Do Until .ReadyState = 4: DoEvents: Loop<o:p></o:p>
 <o:p></o:p>
            Set doc = IE.Document<o:p></o:p>
 <o:p></o:p>
            Set frm = doc.forms("upcform")<o:p></o:p>
 <o:p></o:p>
            doc.all("upc").Value = rngUPC.Text<o:p></o:p>
 <o:p></o:p>
            frm.submit<o:p></o:p>
 <o:p></o:p>
            Do While IE.Busy: DoEvents: Loop<o:p></o:p>
            Do While IE.ReadyState <> 4: DoEvents: Loop<o:p></o:p>
 <o:p></o:p>
            rngUPC.Offset(, 1) = doc.url<o:p></o:p>
 <o:p></o:p>
            Set rngUPC = rngUPC.Offset(1)<o:p></o:p>
 <o:p></o:p>
        Wend<o:p></o:p>
 <o:p></o:p>
        .Quit<o:p></o:p>
<o:p> </o:p>
    End With<o:p></o:p>
 <o:p></o:p>
    Set IE = Nothing<o:p></o:p>
 <o:p></o:p>
End Sub<o:p></o:p>
<o:p></o:p>
 
The fact is we are all trying the code with invalid UPCs and it works.
Maybe the error occurs when you have a valid one. ?!
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,216,471
Messages
6,130,822
Members
449,595
Latest member
jhester2010

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