Hi, long-time listener, first-time caller…
I have about 2 months’ experience programming with VBA. I just wanted to make Excel do a few repetitive tasks for me, and now I’m hooked. I have a whole new respect for the Office suite, now that I know it’s capable of so much. I have a hair-trigger Google finger, so believe me, I really tried to solve this on my own.
I am at my wits' end trying to build a VBA automation for IE. The company has an internal database website where I look up part numbers and get information. It was created with JavaScript. I'd like the macro to go down a spreadsheet and retrieve the information for each part automatically. It should go like this:
<CODE>
</CODE>
<CODE></CODE>
Up to now, everything works fine. The sub pulls up the search page, inserts the part number in the correct field, and submits the search. Now, the search results have come up in the same window. I can click the link that comes up on the page, but couldn’t get it to click programmatically.
Using IE’s built-in Developer Tools to view the source code and hierarchy, I have found an object in there that has a very useful value. I can use this value to navigate straight to the page that contains the part number’s information—call it the “container” number. And, I found a neat trick where VBA can copy innertext from the current IE window (or object within the source code) and deposit it in a string variable.
Here’s what has me banging my head on the desk: I can’t capture that value. I can see it clearly with my eyes, but VBA can’t penetrate the frame. I’ve “walked the nodes” like childnodes(0), childnodes(0).childnodes(0), childnodes(0).childnodes(1) and so on, but every time I try to get into that frame I get “Run-Time error '438': Object Doesn't support this property or method”. I know the trick about setting each frame into its own HTMLDocument, but this hasn’t worked either. I’ve used the names of the objects, to no avail. Every time, I get the error.
Here is a shot of the hierarchy. What path do you think I can put in my code to extract the value of “emxTableRowId”?
http://www.flickr.com/photos/70412643@N06/6392134727/
I use Excel 2007, Windows 7, IE8...thanks for looking
I have about 2 months’ experience programming with VBA. I just wanted to make Excel do a few repetitive tasks for me, and now I’m hooked. I have a whole new respect for the Office suite, now that I know it’s capable of so much. I have a hair-trigger Google finger, so believe me, I really tried to solve this on my own.
I am at my wits' end trying to build a VBA automation for IE. The company has an internal database website where I look up part numbers and get information. It was created with JavaScript. I'd like the macro to go down a spreadsheet and retrieve the information for each part automatically. It should go like this:
<CODE>
</CODE>
Code:
Sub SearchByKeyID()
'This project includes references to "Microsoft Internet Controls" and
'"Microsoft HTML Object Library" – really, it does.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
'Variable declarations
Dim myIE As New InternetExplorer
Dim urlFindItem As String
Dim myDoc As HTMLDocument<o:p></o:p>
Dim c As Range<o:p></o:p>
<o:p></o:p>
'Set starting URL and search string
urlFindItem = "<THE url page search the of>"
<o:p></o:p>
'Make IE navigate to the URL and make browser visible
myIE.Navigate urlFindItem
myIE.Visible = True
'Wait for the page to load
Do While myIE.Busy Or myIE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop
<o:p></o:p>
'Set IE document into object
Set myDoc = myIE.Document
Set c = ActiveCell
'Paste search string on form
myDoc.forms(0).txtName.Value = c.Value
<o:p></o:p>
'Submit form
myDoc.forms(0).submit
'Wait for the page to load
Do While myIE.Busy Or myIE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop
Up to now, everything works fine. The sub pulls up the search page, inserts the part number in the correct field, and submits the search. Now, the search results have come up in the same window. I can click the link that comes up on the page, but couldn’t get it to click programmatically.
Using IE’s built-in Developer Tools to view the source code and hierarchy, I have found an object in there that has a very useful value. I can use this value to navigate straight to the page that contains the part number’s information—call it the “container” number. And, I found a neat trick where VBA can copy innertext from the current IE window (or object within the source code) and deposit it in a string variable.
Here’s what has me banging my head on the desk: I can’t capture that value. I can see it clearly with my eyes, but VBA can’t penetrate the frame. I’ve “walked the nodes” like childnodes(0), childnodes(0).childnodes(0), childnodes(0).childnodes(1) and so on, but every time I try to get into that frame I get “Run-Time error '438': Object Doesn't support this property or method”. I know the trick about setting each frame into its own HTMLDocument, but this hasn’t worked either. I’ve used the names of the objects, to no avail. Every time, I get the error.
Here is a shot of the hierarchy. What path do you think I can put in my code to extract the value of “emxTableRowId”?
http://www.flickr.com/photos/70412643@N06/6392134727/
I use Excel 2007, Windows 7, IE8...thanks for looking