Click Link on Webpage using VBA

mojo215

New Member
Joined
Jan 30, 2008
Messages
9
Hi all,

I'm trying to click a link on a webpage I already have open.

For example say I have google.com open and I wanted to click 'Images' at the top of the page without using the code...

ie.navigate("http://images.google.com/imghp?hl=en&tab=wi")
(I can't use this code b/c the page i'm trying to access requires I click the link)


Is there a way to identify the link on the page by its name and then "click" it?

I've been trying to find code for this all over the place, and it seems impossible to find it...if any one can offer some help I'd appreciate it.

Thanks in Advance
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Well this simple code will open the images page of Google.
Rich (BB code):
Option Explicit
Private Sub GotoGoogleImages()
Dim IE As Object
    Set IE = CreateObject("InternetExplorer.Application")
       
        IE.Visible = True
        IE.Navigate "http://images.google.co.uk/imghp?hl=en&tab=wi"
        
        Do While IE.Busy: DoEvents: Loop
        Do While IE.ReadyState <> 4: DoEvents: Loop
    
End Sub
But I'm pretty sure that's not what you want.:)

I've got 30+ subs that use this sort of code, including stuff that will enter login names/passwords etc.

Also code that will get data from the webpages, mind you nothing that deals with images - so far anyway.:)
 
Upvote 0
Here is an example of John's suggestion :

Code:
Sub Test()
 
    Dim ShellApp As Object
    Dim IEWnd As Object
    Dim Wn As Object
    
    Set ShellApp = CreateObject("Shell.Application")
    Set IEWnd = ShellApp.Windows
    
    For Each Wn In IEWnd
    
        If Wn.Document.Title = "Google" Then
             Wn.Document.Links(0).Click
        End If
    
    Next Wn
 
End Sub

Regards.
 
Upvote 0
Jaafar has already given you the core code. You may also want to check
Using VBA to access the ’Net
http://www.tushar-mehta.com/publish_train/xl_vba_cases/vba_web_pages_services/index.htm

I wish I could supply the URL, its business related and requires a login. If you have some base code for finding a link I'm sure that would be useful and I could try and adapt that.

As in the example I had above...

I have www.google.com open

Now I want to Click the Hyperlink "Images"
How could this be achieved?


Also another possible work around if they above isn't possible...a way to move the mousepointer to specific part of the screen and then pass a left click through that would work fine for me...

I dunno I've just been at my wits end trying to work this out.

Thanks for the help
 
Upvote 0
Even I'm facing the same issue.
The scenario is:
Open an excel sheet "Sheet1" > open "Control toolbox" > Click on "More Controls" > Select "Microsoft Web Browser" > Now you can select the web page length in the sheet. Then type the below code in "Sheet 1" object (Alt+11)

Sub Browse()
Dim URL As String
URL = "http://www.google.com"
Sheets("Sheet1").WebBrowser1.Navigate URL
End Sub

It will get you open the site in the spreadsheet.

Now here is the challenge. I cannot find the solution on how to click say "Images" or "Videos" link which is there at the top left corner of the page using a VB code.

Please help
 
Upvote 0
Well this simple code will open the images page of Google.
Rich (BB code):
Option Explicit
Private Sub GotoGoogleImages()
Dim IE As Object
    Set IE = CreateObject("InternetExplorer.Application")
 
        IE.Visible = True
        IE.Navigate "http://images.google.co.uk/imghp?hl=en&tab=wi"
 
        Do While IE.Busy: DoEvents: Loop
        Do While IE.ReadyState <> 4: DoEvents: Loop
 
End Sub
But I'm pretty sure that's not what you want.:)

I've got 30+ subs that use this sort of code, including stuff that will enter login names/passwords etc.

Also code that will get data from the webpages, mind you nothing that deals with images - so far anyway.:)


Can you please reply with thise documents.
 
Upvote 0
There probably is a way to 'click' the link, but I've got a feeling that you might end up with the same result. ie page expired

I don't see why you think clicking the link would make any difference.:)

The usual reason is that there is Javascript associated with the link that does more than simply navigating to a different page. That's reasonably common on websites run with a backend database.
 
Upvote 0
Scott

Not sure what you mean.

Usually clicking a link is fine, no matter what code is behind it.
 
Upvote 0

Forum statistics

Threads
1,214,665
Messages
6,120,803
Members
448,990
Latest member
rohitsomani

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