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!




 
Does this also work for secure sites? Using navigate with the full path brings me to another site that requires the login credentials again. Maybe this site is secure against programmatically navigating through it? Is there a way to determine this?
 
Upvote 0

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Without the URL it's hard to tell.

What you could try is what I suggested - clicking the button, not the link.

That's if there is a button of course.
 
Upvote 0
Wasn't sure about the button - it has been awhile.

I looked back through the post and see you referred to a button for the initial login.

Try this.
Code:
' code to navigate to site and login
 
For Each objLink In IE.Document.GetElementsByTagName("HREF")
 
   If objLink.href ="sub_searchforjobs.asp?SHOWALLJOBS=1&?x=x" Then
 
      objLink.Click
 
      Exit For
 
    End If
 
Next objLink
Without seeing the actual page that's all I can think of trying right now.
 
Upvote 0
Hello dv512263,

Try this macro. Change the ID and password to match your own.
Rich (BB code):
Sub Macro1A()

  Dim Anchor As Object
  Dim btnSubmit As Object
  Dim ieAnchors As Object
  Dim ieApp As Object
  Dim ieDoc As Object
  Dim ID As String
  Dim Pwd As String
  Dim tbID As Object
  Dim tbPwd As Object
  Dim URL As String
  
      URL = "https://app.aesopcanada.com/login2.asp?id=&serr=ID+or+PIN+is+not+numeric%2C+Please+note+that+you+do+not+have+to+enter+the+pound+%28%23%29+sign."
      
      ID = "Me"
      Pwd = "123"
      
          Set ieApp = CreateObject("InternetExplorer.Application")
          
          ieApp.Navigate URL
          ieApp.Visible = True
          
          While ieApp.Busy: DoEvents: Wend
          
          On Error GoTo ErrHandler
          While ieApp.Document.ReadyState <> "complete": DoEvents: Wend
          
          Set ieDoc = ieApp.Document
          
              Set tbID = ieDoc.getElementById("txtLoginID")
              Set tbPwd = ieDoc.getElementById("txtPassword")
              Set btnSubmit = ieDoc.getElementById("loginLink")
              
              tbID.Value = ID
              tbPwd.Value = Pwd
              btnSubmit.Click
              
                  On Error GoTo ErrHandler
                  While ieApp.Document.ReadyState <> "complete": DoEvents: Wend
                  
                  Set ieAnchors = ieDoc.Anchors
                  
                      For Each Anchor In ieAnchors
                        If Anchor.innerHTML = "Search for Jobs" Then
                           Anchor.Click
                           Exit For
                        End If
                      Next Anchor

ErrHandler:
    If Err <> 0 Then
       MsgBox "Run-time error '" & Err.Number & "':" & vbCrLf & vbCrLf & Err.Decription, vbOKOnly, "Error Opening Web Page"
    Else
       ieApp.Quit
    End If
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,159
Members
452,892
Latest member
yadavagiri

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