VBA - click link in IE using href

dv512263

New Member
Joined
Aug 5, 2011
Messages
13
Hello,

I'm able to navigate to a website, insert user/pswd credentials and click on a button to login and advance. Now I need to navigate through the next site by clicking on a link... this is where I'm having problems. The source code provides a "href" for the link. Does anyone have code to click on this link?

additionally, does anyone have code to time a refresh to occur every 5 seconds?

Any help would be much appreciated!




 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Why do you need to click the link?

Can't you just navigate using the browse to it using the href property for the URL?

What sort of refresh do you mean?

Do you want to refresh the page every 5 seconds?

That might be possible by setting up something using Reload and Application.OnTime.
 
Upvote 0
If it's simpler using navigate to access the next page that would be ok. How do I do this? simply inserting the href into IE.Navigate "href" does not work.

re: the refresh... I'm just trying to refresh the website every 5 seconds and hope to build in some logic to return an alert if a new link becomes available (this will take some work)... code to refresh every 5 seconds would help at this stage. Can you provide some sample code for the reload/Application.OnTime function?
 
Upvote 0
Did you actually use the value of the href property?

That's usually a URL.

I don't have any code for setting up a timer and I'm not sure it's a good idea.

One thing I would be worried about was how long it takes to reload the page each time.

Is it consistent? Is 5 seconds enough time to wait?

Is there a possibility that the process of updating doesn't finish before the next update is scheduled?
 
Upvote 0
What is the actual value of the href? all I can find in the source code is <a href="subsearchforjobs.asp?SHOWALLJOBS=1&?x=x". I've tried using IE.Navigate "subsearchforjobs.asp?SHOWALLJOBS=1&?x=x"...but it doesn't work.


I think the following will deal with the concerns you've mentioned re: the refresh.

While IE.Busy
DoEvents
Wend

anyone else have any ideas?
 
Upvote 0
The start of the anchor(link) should look something like this in the source code
HTML:
<a href="...">
You want the but between the quotes after href.

That might not be a 'full' URL so you would need to add on the first part which will probably be the base URL for the site.


That's a standard loop that's used to wait for the page to load in IE, not sure how that would work with something scheduled in Excel
 
Upvote 0
bump

haven't had time to get back to this project in the past 10 days...

I am able to navigate to www.aesopcanada.com enter my id and pin and advance by clicking on the LOGIN button. On the following page I need to select a link with the following source code.

Code:
<INPUT class=SYN_LNN value=290 type=label unselectable="on"><INPUT id=syn_ctrl290 class=SYN_BCH role=button value=- type=label unselectable="on">
						[COLOR=#0000ff]<[/COLOR][COLOR=#800000]tr[/COLOR][COLOR=#0000ff]>[/COLOR][COLOR=#0000ff]<[/COLOR][COLOR=#800000]td[/COLOR][COLOR=#0000ff] [/COLOR][COLOR=#ff0000]align[/COLOR][COLOR=#0000ff]=right>[/COLOR][COLOR=#0000ff]<[/COLOR][COLOR=#800000]img[/COLOR][COLOR=#0000ff] [/COLOR][COLOR=#ff0000]src[/COLOR][COLOR=#0000ff]='..//includes/arrow.gif'>[/COLOR][COLOR=#0000ff]</[/COLOR][COLOR=#800000]td[/COLOR][COLOR=#0000ff]>[/COLOR]


<INPUT class=SYN_LNN value=291 type=label unselectable="on"><INPUT id=syn_ctrl291 class=SYN_BCH role=button value=- type=label unselectable="on">
							[COLOR=#0000ff]<[/COLOR][COLOR=#800000]td[/COLOR][COLOR=#0000ff] [/COLOR][COLOR=#ff0000]valign[/COLOR][COLOR=#0000ff]=top>[/COLOR][COLOR=#0000ff]<[/COLOR][COLOR=#800000]a[/COLOR][COLOR=#0000ff] [/COLOR][COLOR=#ff0000]href[/COLOR][COLOR=#0000ff]="sub_searchforjobs.asp?SHOWALLJOBS=1&?x=x" [/COLOR][COLOR=#ff0000]class[/COLOR][COLOR=#0000ff]="homeMenu">[/COLOR]Search for Jobs[COLOR=#0000ff]</[/COLOR][COLOR=#800000]a[/COLOR][COLOR=#0000ff]>[/COLOR][COLOR=#0000ff]</[/COLOR][COLOR=#800000]td[/COLOR][COLOR=#0000ff]>[/COLOR][COLOR=#0000ff]</[/COLOR][COLOR=#800000]tr[/COLOR][COLOR=#0000ff]>[/COLOR]


Does anyone know how to do this? thank you and I apologize for bringing this topic back after a 10 day hiatus.
 
Upvote 0
I should also mentioned that Norie's suggestion is not working for me - unless I'm doing something wrong (below)

Code:
IE.Navigate "[COLOR=#0000ff]sub_searchforjobs.asp?SHOWALLJOBS=1&?x=x"[/COLOR]
 
Upvote 0
As Norie said, the href in the HTML source is a relative URL (relative to the site/domain), so you need to prepend it with the full domain and path. For example:
Code:
IE.Navigate "http://www.aesopcanada.com/sub_searchforjobs.asp?SHOWALLJOBS=1&?x=x"
That URL might be incomplete or wrong so hover over the link in your browser (or copy link) to determine the actual complete URL and use that in your code.
 
Upvote 0
You might be able check what the full URL should be by right clicking the link and selecting properties, but I'm pretty sure John has it right.

If it still doesn't work then you can always try clicking the button if there is one.
 
Upvote 0

Forum statistics

Threads
1,224,504
Messages
6,179,142
Members
452,892
Latest member
JUSTOUTOFMYREACH

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