Wait until user navigates away from current internet explorer webpage THEN run VBA code

killpaddy

Board Regular
Joined
Jul 31, 2012
Messages
52
Hello,

I have a piece of code that opens a webpage in internet explorer.
I then want the next section of the code (just picks information off the webpage referring to specific elements) to run only when 'the user' types in a search and navigates to the search results page. The program would then revert back to the original search page and repeat the process.

This is the code i have so far:

Code:
Set ie = New InternetExplorerMedium
ie.Visible = True


'sets up loop to load webpage ready for new info to be entered on each pass
For i = 1 to lastrow

'open webpage
ie.navigate "about:blank"ie.navigate ("http://www.mrexcel.com/forum/")

'wait to load
Do
    If ie.ReadyState = 4 Then
         Exit Do
     Else
         DoEvents
     End If
Loop


'Wait to load AND for user to navigate away from webpage
Do
    If ie.ReadyState = 4 And Not *??? ie.address = "http://www.mrexcel.com/forum/" ???* Then
'Another wait needed???
        ie.Document.getelementbyid("quick_search_input").Value = PRODREF
        ...
        ...


         Exit Do
     Else
         DoEvents
     End If
Loop

'Performs actions with 'PRODREF' and other retrieved variables from the webpage

Next

*??? what needs to go in this gap in code ???*

Will I also need to add another Do loop to wait for the new webpage to load when the user has navigated to it?

I realise this method leaves room for error in that if a different link is clicked by the user, the next section of code looking at specific webpage elements may not work. However, I will be the only person using the code, so this doesnt matter.

Thank you in advance,

killpaddy
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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