Reputation: 2508
I am trying to parse a webpage but am having difficulty in getting the information coming through.
I have a simple button which navigate to a website in a worksheet
Private Sub Sellit_Click()
Dim IE As Object
Dim HTMLDoc As HTMLDocument
Dim oHTML_Element As IHTMLElement
Set IE = CreateObject("Internetexplorer.Application")
IE.Visible = True
apiShowWindow IE.hwnd, SW_MAXIMIZE
IE.navigate "https://www.yahoo.com/"
Do
Loop Until IE.ReadyState = READYSTATE_COMPLETE
DoEvents
Scrape
End Sub
While the function Scrape in a module
Function Scrape()
Dim IE As Object
Dim HTMLDoc As HTMLDocument
Dim oHTML_Element As IHTMLElement
MsgBox IE.document.Title
End Function
I kinda think i know the problem here is the IE doesn't go from the worksheet to the module and vise versa but am not quite sure how to fix it.
your help will be much apperciated
Upvotes: 1
Views: 298
Reputation: 5780
You'd have to declare the IE
object variable publicly, then refer to it using it's fully qualified name. To do so:
Worksheet
code module type Public IE as Object
IE
within the SellIt
Click event and the Scrape
function. Since this is declared publicly, it shouldn't be declared privately within the code.IE
declaration. (Same reason as step 2)MsgBox IE.document.Title
to include the sheet's codename. For example, if the sheet codename is Sheet1
it should read MsgBox Sheet1.IE.document.Title
Let me know if that helps.
Upvotes: 2