VBA code to open a site (intranet) and look for the link name (MyLink) and click.

200yrs

New Member
Joined
Nov 27, 2015
Messages
6
Hello Team...so below is my code...I cant get it to work...please help...thanks.


Code:
[COLOR=blue]Sub[/COLOR] Button1_Click() 
     
     
    [COLOR=blue]Dim[/COLOR] internet [COLOR=blue]As[/COLOR] [COLOR=blue]Object[/COLOR] 
    [COLOR=blue]Dim[/COLOR] internetdata [COLOR=blue]As[/COLOR] [COLOR=blue]Object[/COLOR] 
    [COLOR=blue]Dim[/COLOR] div_result [COLOR=blue]As[/COLOR] [COLOR=blue]Object[/COLOR] 
    [COLOR=blue]Dim[/COLOR] header_links [COLOR=blue]As[/COLOR] [COLOR=blue]Object[/COLOR] 
    [COLOR=blue]Dim[/COLOR] link [COLOR=blue]As[/COLOR] [COLOR=blue]Object[/COLOR] 
    [COLOR=blue]Dim[/COLOR] URL [COLOR=blue]As[/COLOR] [COLOR=blue]String[/COLOR] 
     
     
    [COLOR=blue]Set[/COLOR] internet = CreateObject("InternetExplorer.Application") 
    internet.Visible = [COLOR=blue]True[/COLOR] 
     
     
    URL = "http://web.myweb.com/location/myplace/en-US/OnD/RH/RH%20Form/Pages/default.aspx" 
    internet.Navigate URL 
     
     
    [COLOR=blue]While[/COLOR] internet.ReadyState >= 4 
        DoEvents 
    [COLOR=blue]Wend[/COLOR] 
     
     
    Application.Wait Now + TimeSerial(0, 0, 5) 
     
     
    [COLOR=blue]Set[/COLOR] link = ie.document.getElementsByTagName("a") 
     
    [COLOR=blue]For Each[/COLOR] h [COLOR=blue]In[/COLOR] header_links 
        [COLOR=blue]If[/COLOR] h.innerText = "MyLink" [COLOR=blue]Then[/COLOR] 
            [COLOR=blue]Set[/COLOR] link = h.ChildNodes.Item(0) 
            link.Click 
             
             
        [COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR] 
         
    [COLOR=blue]Next[/COLOR] 
     
     
[COLOR=blue]End Sub[/COLOR]
 

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.

Forum statistics

Threads
1,226,730
Messages
6,192,698
Members
453,747
Latest member
tylerhyatt04

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