Navigate in ie from excel using source code in web page

chrisbrocco

Board Regular
Joined
Mar 31, 2005
Messages
82
Hi all, i am trying to make excel open a web page then naviagte to a link. I know how to do this if the link has the same address all the time using

Set ie = CreateObject("InternetExplorer.Application")

With ie
.Visible = True
' Go to web page
.navigate "http://www.google.co.uk/imghp?hl=en&tab=wi"

Do Until .readyState = 4
DoEvents
Loop

but how could I navigate to a link which continually changes.

for example on a web page the link always shows "report", but the actual address may changes say every hour.

Is there a way to navigate to what ever address sits behind "report"
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
Chris

Is the URL you've posted 'genuine'?

If it is I'll try and take a look at it.

Also you say the link always displays as Report?
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Chris

I could help with this, if you posted 'real' URL's.

Without them I can only really give general advice.

For example here's a piece of code that I helped another member with.
Code:
Sub Test()
Dim lnk
    Set ie = CreateObject("InternetExplorer.Application")
    With ie
        .Visible = True
        .Navigate "http://www.nu.nl/"
        Do Until .ReadyState = 4: DoEvents: Loop
       
        Set doc = ie.document
    
        Open "C:\TestHTML.txt" For Output As #1
            For Each lnk In doc.links
                Print #1, lnk
            Next lnk
        Close #1
    End With
    
End Sub
I realise this isn't exactly what you are looking for but it might give you some ideas.
 

chrisbrocco

Board Regular
Joined
Mar 31, 2005
Messages
82
I see very clever. So if in the TestHTML.txt I want to navigate to the first link how would i do that
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Chris

What the posted code does is create a text file containing all the links on the webpage.

This part of it loops through all the links and writes the to the text file.
Code:
For Each lnk In doc.links
     Print #1, lnk
Next lnk
Hopefully that will give you some ideas, but like I said it's hard to help with this sort of thing without valid URLs.

You could probably put some sort of If in the loop to find the link you want and then navigate to it.

Here's a <a href="http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/dhtml_reference_entry.asp
">link</a> that might help.
 

chrisbrocco

Board Regular
Joined
Mar 31, 2005
Messages
82
ok I have an idea. if I change it to:

Open "C:\TestHTML.xls" For Output As #1

the link I want is in cell A1

what would be the code to navigate to C:\TestHTML.xls cell A1

many thanks again
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
chris

I'm still unsure what you exactly want to do.

Can you explain further?
 

chrisbrocco

Board Regular
Joined
Mar 31, 2005
Messages
82
I want to goto web page A, and navigate within this web page to link B which addess changes (due to updates) every hour or so.

As the address changes every hour I cant use

With ie
.Visible = True
' Go to web page
.navigate "http://www.B.co.uk/"

because an hour later it would be http://www.B1.co.uk/

so I need a way to find the address ( as your code does) and then navigate to the new address in cell A1

The code you have sent works perfectly, all I need to do now is:

k = "C:\TestHTML.xls cell A1" (which I now is wrong)

With ie
.Visible = True
' Go to web page
.navigate K

And this should work

any ideas how to write k = "C:\TestHTML.xls cell A1" in the correct format
 

Forum statistics

Threads
1,136,369
Messages
5,675,360
Members
419,565
Latest member
Phil57

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
Top