Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 20th, 2006, 06:03 PM
Registered User
 
Join Date: Nov 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default sending keystrokes to www.whereis.com.au

Hi, I managed to open the web site by using the VB in Excel but I cannot send the keystrokes to the site(go directions), can anyone help.

Sub getdirection()

'log into csweb.tpg.com.au

Dim ie As Object
  Set ie = CreateObject("InternetExplorer.Application")
     ie.Visible = True
     ie.navigate "http://www.whereis.com/whereis/directions.do"

     Do While ie.Busy And Not ie.ReadyState = 4:
         Application.Wait (Now + TimeValue("0:00:02"))
         DoEvents
     Loop

   ie.document.getElementById("addressStreetNo0").Val ue = "65"
   ie.document.getElementById("addressStreetName0").V alue = "Waterloo Road"
   ie.document.getElementById("addressSuburb0").Value = "Mosman"
   ie.document.getElementById("addressState0").Value = "NSW"


Set ipf = ie.Document.all.Item("cmd")
ipf.Click



 
Old November 21st, 2006, 05:46 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 173
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Is this what you need?

Code:
Sub getdirection()
' Log into csweb.tpg.com.au

Dim ie As Object

    Set ie = CreateObject("InternetExplorer.Application")
    ie.Visible = True
    ie.navigate "http://www.whereis.com/whereis/directions.do"

    WaitForLoad ie

    ie.Document.getElementById("addressStreetNo0").Value = "65"
    ie.Document.getElementById("addressStreetName0").Value = "Waterloo Road"
    ie.Document.getElementById("addressSuburb0").Value = "Mosman"
    ie.Document.getElementById("addressState0").Value = "NSW"

    ie.Document.getElementById("addressStreetNo3").Value = "65"
    ie.Document.getElementById("addressStreetName3").Value = "Waterloo Road"
    ie.Document.getElementById("addressSuburb3").Value = "Mosman"
    ie.Document.getElementById("addressState3").Value = "NSW"

    ie.Document.getElementById("btnGetDirections").Click

End Sub

Private Sub WaitForLoad(IExp As Object)
' Wait for page to load before continuing

Dim sngTime As Single

Const MaxTime As Integer = 10

    sngTime = Timer

    ' Wait until the webpage is doing something ...
    Do Until IExp.readyState <> 4
        DoEvents
        If Timer > sngTime + MaxTime And Left(IExp.StatusText, 4) = "Done" Then Exit Sub
    Loop

    ' ... and then wait for it to finish
    Do Until IExp.readyState = 4
        DoEvents
        If Timer > sngTime + MaxTime And Left(IExp.StatusText, 4) = "Done" Then Exit Sub
    Loop

End Sub
 
Old November 21st, 2006, 07:30 AM
Registered User
 
Join Date: Nov 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes, tks but it seems on the private sub part, my excel has not got an error Message:"complie error, cannot find the project or Library" and highlighted the word "left". I guess I have not intalled the right dll. would you pse advise what to do.



 
Old November 21st, 2006, 07:35 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 173
Thanks: 0
Thanked 3 Times in 3 Posts
Default

The Left function is part of the VBA library (in the strings module) and so should always be available. It sounds to me like you've got a missing reference clogging up the system. Could you go to Tools -> References... and uncheck any items that start with MISSING: (or something like that)

 
Old November 21st, 2006, 07:56 AM
Registered User
 
Join Date: Nov 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, it is working now. However, infact my objective is to obtain the total Km and total time after having automated input the from (address0) and to (address1), I still got the other problem as if either the address0 or address1 is not clear, it will bring you to another web site to confirm with you the address, then it brings you to the final page which shows you the total km and the mins used to travel from one place to the other.

Therefore, I have two obstacles, one is to pass thro' the second web site(confirming the address if it is unclear) and then extracting the total km and mins from the final page.

here is the script with the addresses.

Sub getdirection1()
' Log into csweb.tpg.com.au

Dim ie As Object

    Set ie = CreateObject("InternetExplorer.Application")
    ie.Visible = True
    ie.navigate "http://www.whereis.com/whereis/directions.do"

    WaitForLoad ie

    ie.document.getElementById("addressStreetNo0").Val ue = "65"
    ie.document.getElementById("addressStreetName0").V alue = "Waterloo Road"
    ie.document.getElementById("addressSuburb0").Value = "North Ryde"
    ie.document.getElementById("addressState0").Value = "NSW"

    ie.document.getElementById("addressStreetNo3").Val ue = "414"
    ie.document.getElementById("addressStreetName3").V alue = "Military Road"
    ie.document.getElementById("addressSuburb3").Value = "Cremone"
    ie.document.getElementById("addressState3").Value = "NSW"

    ie.document.getElementById("btnGetDirections").Cli ck

End Sub

Private Sub WaitForLoad(IExp As Object)
' Wait for page to load before continuing

Dim sngTime As Single

Const MaxTime As Integer = 10

    sngTime = Timer

    ' Wait until the webpage is doing something ...
    Do Until IExp.readyState <> 4
        DoEvents
        If Timer > sngTime + MaxTime And Left(IExp.statusText, 4) = "Done" Then Exit Sub
    Loop

    ' ... and then wait for it to finish
    Do Until IExp.readyState = 4
        DoEvents
        If Timer > sngTime + MaxTime And Left(IExp.statusText, 4) = "Done" Then Exit Sub
    Loop

End Sub



 
Old November 21st, 2006, 08:08 AM
Registered User
 
Join Date: Nov 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

tks and it works. However, my objective is to get the total km and mins from the final page. However, there are two obstacles. One, if either of address0 or address1 is unclear, another webpage will pop up and asking to confirm the addresses, then it will bring you to the final page and show you the total km and mins.

All I have to do is to extract the total km and mins from that page and put into a cell in excel. can you suggest what to do?

I have here an example of the addresses.

Sub getdirection1()
' Log into csweb.tpg.com.au

Dim ie As Object

    Set ie = CreateObject("InternetExplorer.Application")
    ie.Visible = True
    ie.navigate "http://www.whereis.com/whereis/directions.do"

    WaitForLoad ie

    ie.document.getElementById("addressStreetNo0").Val ue = "65"
    ie.document.getElementById("addressStreetName0").V alue = "Waterloo Road"
    ie.document.getElementById("addressSuburb0").Value = "North Ryde"
    ie.document.getElementById("addressState0").Value = "NSW"

    ie.document.getElementById("addressStreetNo3").Val ue = "414"
    ie.document.getElementById("addressStreetName3").V alue = "Military Road"
    ie.document.getElementById("addressSuburb3").Value = "Cremone"
    ie.document.getElementById("addressState3").Value = "NSW"

    ie.document.getElementById("btnGetDirections").Cli ck

End Sub

Private Sub WaitForLoad(IExp As Object)
' Wait for page to load before continuing

Dim sngTime As Single

Const MaxTime As Integer = 10

    sngTime = Timer

    ' Wait until the webpage is doing something ...
    Do Until IExp.readyState <> 4
        DoEvents
        If Timer > sngTime + MaxTime And Left(IExp.statusText, 4) = "Done" Then Exit Sub
    Loop

    ' ... and then wait for it to finish
    Do Until IExp.readyState = 4
        DoEvents
        If Timer > sngTime + MaxTime And Left(IExp.statusText, 4) = "Done" Then Exit Sub
    Loop

End Sub







Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple Keystrokes (Java 5) NEO1976 Pro Java 0 February 29th, 2008 06:44 AM
Sending Keystrokes to Application [email protected] Pro VB.NET 2002/2003 1 January 18th, 2005 12:53 PM
Scrolling thru a large list box - using keystrokes bill unswort VBScript 1 August 27th, 2004 07:20 AM
Hiding text keystrokes for passwords mmcdonal Access VBA 4 March 16th, 2004 04:18 PM
Hiding Keystrokes kromlic Beginning VB 6 3 June 12th, 2003 04:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.