VBA to Click Link

hesco

New Member
Joined
Jul 3, 2015
Messages
8
I have been searching for a way to click a link with VBA. I can navigate to the page and do all the steps but, for the life of me can not find the answer to how to click this button. I can't use the href as it changes each month and I would like to make this as simple as possible. Maybe I am just attacking it all wrong? So I come here for your help.

Code:
Sub iepart1()Dim ie As Object
Dim pass As String
Dim user As String
Dim Obja As Object




user = InputBox("Enter your Username: ")
pass = InputBox("Enter your password: ")
Set ie = CreateObject("internetexplorer.application")


' Open Internet Explorer


With ie
    .Visible = True
    .Navigate "https://jonnystart.imakenews.com"


Do While .busy
    DoEvents
Loop
' waits until IE is in a ready state


Do While .readystate <> 4
    DoEvents
Loop
' Ready to move ahead with next command once .readystate<>4
' logs on to account name
' input what column to use for account name selection


ie.Document.All("accountName").Value = "acuraofseattle"
    .Document.forms(0).submit
Do While .busy
    DoEvents
Loop
' waits until IE is in a ready state


Do While .readystate <> 4
    DoEvents
Loop
'Insert UserName and password
ie.Document.All("usermail").Value = user
ie.Document.All("PIN").Value = pass
    .Document.forms(0).submit


Do While .busy
    DoEvents
Loop
' waits until IE is in a ready state


Do While .readystate <> 4
    DoEvents
Loop


 Set Obja = ie.Document.getElementsByTagName("a")
        If Link.innerHTML = "Post to the Web" Then
        Link.Click




End If
End With


End Sub

Here is the information from the webpage that I am trying to have IE click for me.

HTML:
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Replace-
Code:
  Set Obja = ie.document.getElementsByTagName("a")
        If Link.innerHTML = "[COLOR=#333333]Post to the Web[/COLOR]" Then
        Link.Click

with-

Code:
For Each l In ie.document.getElementsByTagName("a")
    If l.innerHTML = "[COLOR=#333333]Post to the Web[/COLOR]" Then
        l.Click
        Exit For
    End If
Next
 
Upvote 0
Replace-
Code:
  Set Obja = ie.document.getElementsByTagName("a")
        If Link.innerHTML = "[COLOR=#333333]Post to the Web[/COLOR]" Then
        Link.Click

with-

Code:
For Each l In ie.document.getElementsByTagName("a")
    If l.innerHTML = "[COLOR=#333333]Post to the Web[/COLOR]" Then
        l.Click
        Exit For
    End If
Next

It skips right over the For Loop like it isn't even there. Which is super strange to me..
 
Upvote 0

Forum statistics

Threads
1,215,669
Messages
6,126,120
Members
449,293
Latest member
yallaire64

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