PDA

View Full Version : How Can I?



dgs2001
12-12-2008, 02:34 PM
Hi

I am trying to get to grips with Automating IE.

I am tryng this code


Set goIe = CreateObject("InternetExplorer.Application")

With goIe

.Visible = True
.Navigate "myURL"& myDate
Do Until (.ReadyState = 4 And Not .Busy): DoEvents: Loop

However when using this with Vista and Excel 2007 , I get 2 windows open and only one of them shows the URL, the other just gets stuck at connecting.
myURL is correctly set by previous code as is myDate
Thanks Duncan

Zack Barresse
12-12-2008, 02:42 PM
Hi there, welcome to the board!!

Are you sure it's not a previous window you've created? Can you post all of your code? And why is "myURL" in quotes? Is that an actual variable? You elude to it, but if so it does not need to be in quotes. It works for me, and I only get one instance. I had to dummy up the code a bit as you didn't post much...

Option Explicit

Sub dljsldkjlksdj()

Dim goIE As Object, myDate As Variant
myDate = "http://www.google.com/"

Set goIE = CreateObject("InternetExplorer.Application")
With goIE
.Visible = True
.Navigate myDate 'altered for testing
Do Until (.ReadyState = 4 And Not .Busy): DoEvents: Loop
End With

goIE.Quit

End Sub

mdmackillop
12-12-2008, 02:49 PM
or even "allude" :beerchug:

dgs2001
12-12-2008, 02:49 PM
Thank you for your fast response.

I have open an IE window with 4 tabs.
Also an excel workbook.
I paste your code into a module.

On running your code I get a new tab opens on my existing IE window which navigates to google. (Hooray!!)

I also get a new window which just stays at connecting. (Boo!)

Any ideas?

Duncan

dgs2001
12-12-2008, 02:53 PM
AAHHAA

An Idea dawns,

I have two home pages set in IE.

Every time I fire up IE I get two pages showing on two tabs.

I'm off to imediatley delete a home page!!!!

Duncan

dgs2001
12-12-2008, 03:08 PM
Nope That did'nt work. :banghead:

Here is the complete code


Sub login()
Dim myDate As Date
Dim myregex As Object
Dim goIE As Object
Dim iedoc
Dim mylnk
Dim myMatches
Dim myMatch
Dim myStr As String
Dim myRow As Integer
myDate = InputBox("Enter RaceDate as yyyy-mm-dd", Default:=Format(Now, "yyyy-MM-dd"))

Set myregex = CreateObject("VBScript.RegExp")
With myregex
.Pattern = "\d{6}"
.Global = True
.IgnoreCase = False
End With

Set goIE = CreateObject("InternetExplorer.Application")

With goIE

.Visible = True
.Navigate "thisbitmissing.racingpost.com/horses/racing.sd?r_date=" & myDate
Do Until (.ReadyState = 4 And Not .Busy): DoEvents: Loop

myStr = ""
myRow = 1

Set iedoc = goIE.document

For Each mylnk In iedoc.Links

If InStr(mylnk, "race_id") Then
Set myMatches = myregex.Execute(mylnk)
If myMatches.Count > 0 Then
myMatch = myMatches(0)
If InStr(myStr, myMatch) = 0 Then
Worksheets("RacingPost Id's").Cells(myRow, 1) = myMatch
myRow = myRow + 1
myStr = myStr & "," & myMatch
End If
End If
End If

Set myMatches = Nothing

Next mylnk
End With ' This bit of code navigates to the runners index page and holds it in a variable called ieDoc.

End Sub


As you can see I am trying to gather some horse racing data to excel.

However my initial problem is that as stated I end up with two windows 1 stays at connecting and the code never gets past the DoUntil Loop

ps thisbitmissing is the httpwww bit!!

dgs2001
12-13-2008, 09:26 AM
Anyone have anyideas??