>>I need to populate an Excel file with values from a browser.
We can do that...
>>I have the links in an Excel file, I need to go through each one and take all the data and put it into a spreadsheet.
Can you expand on this...?
Are they in a list of cells?
If so (I'm guessing they are) I will show you how to select them, Then loop through the Selection
>>I understand this is possible with a Web Browser control. However I know nothing about it.
First, (Assuming you are using the VBA IDE in excel) you'll need to set a reference (Tools>References...) to:
Microsoft Internet Controls
and
Microsoft HTML Object Library
...this will contain your
WebBrowser Object that you need...
>>I'd really like to do it from Excel VBA, so I know I'm in the wrong forum. However when I did a search I came up with posts in this forum, and I don't know if I can use it in Excel.
No Problem. Just as long as YOU KNOW that there is a VBA forum...
This particular question leans more towards the VB5/6 side anyway (in other words, I would do the same thing)
And... Yes you CAN use it in excel...
>>Would anyone be able to give me a starting point?
Sure...
after setting the reference that you need (mentioned above)
You need to create a macro Sub and create the Object...
Code:
Sub GetInfoFromWeb()
Dim wb1 As WebBrowser
Dim Doc As HTMLDocument
Dim Cell As Range
For Each Cell In Selection
Set wb1 = CreateObject("InternetExplorer.Application")
wb1.Navigate2 Site
Do: DoEvents: Loop Until wb1.ReadyState = READYSTATE_COMPLETE
Set Doc = wb1.Document
'Get Data from document...
'Process and write to output...
wb1.Quit
Set wb1 = Nothing
Next
End Sub
Now, for further help, I need to have an example of the target site(s) source code, to know how you need to access the data... (there are several ways, some easier than others)
For a simple Example...
If you want to dump the source to a new sheet you can do this:
Code:
Sub GetInfoFromWeb()
Dim wb1 As WebBrowser
Dim Doc As HTMLDocument
Dim Sheet As Worksheet
Dim SheetNum As Integer
Dim Cell As Range
For Each Cell In Selection
If Cell.Text <> "" Then
Set wb1 = CreateObject("InternetExplorer.Application")
'wb1.Visible = True
wb1.Navigate2 Cell.Text
Do: DoEvents: Loop Until wb1.ReadyState = READYSTATE_COMPLETE
Set Doc = wb1.Document
Set Sheet = Worksheets.Add(After:=Worksheets.Item(Worksheets.Count))
On Error Resume Next
Do
Err = 0
SheetNum = SheetNum + 1
Sheet.Name = "WebSheet" & SheetNum
Loop Until Err = 0
ActiveCell = Doc.body.innerHTML
wb1.Quit
Set wb1 = Nothing
On Error GoTo 0
End If
Next
End Sub
Since there are seemingly, endless ways to create webpages, you would have to know what the source looks like to be able to work with the file...
The above example is to show that you do have access to the Document Object...
PROGRAMMER:
Red-eyed, mumbling mammal capable of conversing with inanimate objects.