Automating already open IE Window

Buggington

New Member
Joined
Mar 28, 2014
Messages
8
Hello - first post here :)

I'm a VBA newbie and haven't really started with the easiest project! I'm trying to pull some data out of a website using a VBA macro and would like it to use an existing IE window (as it requires user intevention to find the correct page in the first place - this will change each time the script is run).

I've been doing some research and the best solution I've been able to find so far is this, which I've copied word for word.

Code:
Sub FindTicketWindow()
'loop through each window
For Each wd In CreateObject("Shell.Application").Windows
    'test it
    If wd = "Windows Internet Explorer" Then
        If InStr(UCase(wd.Document.Title), "Yahoo") <> 0 Then
            'rejoice, found it!
            Exit For
        End If
    End If
Next wd
wd.Navigate "[URL="http://www.google.com"]Google[/URL]"
End Sub

I haven't started customising it for my own use yet, but when I try to step through it I get runtime error 438 when it hits the following line:

Code:
If InStr(UCase(wd.Document.Title), "Yahoo") <> 0 Then

Any ideas what might be causing this?

Thanks :)
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
try this

Code:
Sub FindTicketWindow()'loop through each window
For Each wd In CreateObject("Shell.Application").Windows
    'test it
    If wd.Name = "Internet Explorer" Then
        If InStr((wd.document.Title), "Yahoo") <> 0 Then
            'rejoice, found it!
            Exit For
        End If
    End If
Next wd
    wd.Navigate "Google"
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

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