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>
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
well - this works fine for me.

doc.all("upc").Value = rngUPC.Text
This line fills the textbox to search by. Here is the HTML:

HTML:
<p>
<form name="upcform" method="get" action="item.asp" onsubmit="**************** = 'http://www.upcdatabase.com/item/' + this.elements.upc.value; return false;">
<input type=text name=upc size=16 maxlength=13 stiscan stisubmit>
<input type=submit value=" Look Up UPC ">
</form>
</p>

if the all("upc") reference doesn't work for you - try to find the right way to address this control (textbox, control, input ... who knows )
 
Upvote 0
bobsan42,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
I'm not very technical, so I don't understand most of what you said. However, when you said it worked fine for you, did you try a column of more than 1 number? Because it is only when that column is longer than one that I receive the error.<o:p></o:p>
<o:p></o:p>
Any specific changes to my code you might suggest?<o:p></o:p>
<o:p></o:p>
Thanks,<o:p></o:p>
Bub******** type=text/javascript> vbmenu_register("postmenu_2389518", true); *********> <o:p></o:p>
<o:p> </o:p>
 
Upvote 0
Bub

Are those definitely valid UPCs?

I ran the code and it worked with no errors but every URL returned was http://www.upcdatabase.com/upcerror.asp.

That indicates a problem with the UPCs rather than the code.

One thing you could try is adding .Visible = True after With IE.

Then run through the code using F8 and flicking between IE and VBE.

That should mean that you'll see IE being opened, the search page navigated to, the number being entered and then the 'Look Up UPC' button clicked.

Mind you with all the nos above you'll end up being told the UPC is incorrect or invalid.:)

PS This is a response to your last post that had sample data - I'm getting a little confused as to where to post on this topic.:eek:

That's one of the reasons you shouldn't create duplicate threads but stick to the original as Joe suggested.
 
Upvote 0
Norie,

That is the point. Most of my 7500+ UPCs I expect to be invlaid. This is my way of weeding out the bad UPCs.

Sorry, I didn't read the rules prior to posting.

What does F8 do?

Thanks,
Bub
 
Upvote 0
Bub

You use F8 to step through the code line by line.

That should make it possible for you to see what is happening.

As for the UPCs being invalid, that's kind of irrelevant.

Like I said I ran the code, it worked fine and gave me a result for each UPC searched for.

The result was the invalid/incorrect message but it was a result.:)
 
Last edited:
Upvote 0
Norie,

I don't understand. When I used F8 to run through it, it worked! But when I just hit run, it gives me that error. What is going on?

Very confused,
Bub
 
Upvote 0
Bub

That sounds like a problem with your browser, connection, the internet the web etc

Does any part of the process seem to take longer than you would expect?

For example pages loading in the browser?

Try adding this after .Navigate.
Code:
Do While .Busy: DoEvents: Loop
That should make the code wait until the search page is loaded.

I don't know if it'll help but it's all I can think of right now.
 
Upvote 0
Norie,

I'll try that, but I'll probably end up just holding something on the F8 key and walking away.

Thank you for all your help and patience.

Cheers,

Bub
 
Upvote 0
As well as Norie's suggestion, try replacing:

Set doc = IE.Document

With:

While .Document.readystate <> "complete": DoEvents: Wend
Set doc = .Document
 
Upvote 0

Forum statistics

Threads
1,214,874
Messages
6,122,034
Members
449,061
Latest member
TheRealJoaquin

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