dleads
asked on
How to Click on IE link using VBA
I am able to navigate to a webpage that lists all of the courts. Once there, my vba code determines which court to go to. I find it in the list, but then I do not know how to get it to click on that link.
This is an example of the source for one of the courts I'd like to click on. My code finds the 'Alabama Northern District Court', but then how do I click it?
I need to grab ....https://ecf.alnd.uscourts.gov.... and select that link
strfoundcourtname = ?grab the https link somehow
ie.Document.all.Item(strfo undcourtna me).Click
How would I do that?
<TR valign=center align=left>
<TD><IMG src=/images/pscovl1.gif hspace=10 alt=*>
<A href=https://ecf.alnd.uscourts.gov/ class=linktxt>
Alabama Northern District Court </A> - <font size="1" color="#800517"><b>CM/ECF- DC V3.2.1</b></font> <A href=http://pacer.psc.uscourts.gov/psco/cgi-bin/courtinfo.pl?court=E_ALNDC TITLE="Court Information" class=linktxt> <IMG STYLE="border: none;" SRC="/images/courtinfo.png " ALT="Court Info"></A>
</TD></TR>
TIA
This is an example of the source for one of the courts I'd like to click on. My code finds the 'Alabama Northern District Court', but then how do I click it?
I need to grab ....https://ecf.alnd.uscourts.gov.... and select that link
strfoundcourtname = ?grab the https link somehow
ie.Document.all.Item(strfo
How would I do that?
<TR valign=center align=left>
<TD><IMG src=/images/pscovl1.gif hspace=10 alt=*>
<A href=https://ecf.alnd.uscourts.gov/ class=linktxt>
Alabama Northern District Court </A> - <font size="1" color="#800517"><b>CM/ECF-
</TD></TR>
TIA
ASKER
Thanks for repsonding Jeff.
I am attempting to automate the selection of a link on a webpage (that has many links listed).
The example I provided shows just one state (Alabma). My Access form will state which State is required. The user will then click a button that will go to the site, find the State in the list and then go to that particular State's website. I need to figure out how to get the hyperlink of the state and click on it.
So my question is this... How would I code VBA to to find a specific state, in this case Alabama, and click on the hyperlink. The source code of the webpage, for just this Alabama example, is as follows:
<TR valign=center align=left>
<TD><IMG src=/images/pscovl1.gif hspace=10 alt=*>
<A href=https://ecf.alnd.uscourts.gov/ class=linktxt>
Alabama Northern District Court </A> - <font size="1" color="#800517"><b>CM/ECF- DC V3.2.1</b></font> <A href=http://pacer.psc.uscourts.gov/psco/cgi-bin/courtinfo.pl?court=E_ALNDC TITLE="Court Information" class=linktxt> <IMG STYLE="border: none;" SRC="/images/courtinfo.png " ALT="Court Info"></A>
</TD></TR>
How would I programmatically find the "<A href=https://ecf.alnd.uscourts.gov/ class=linktxt>" and click on the link?
I do not want the user to manually click on it - I'm trying to get it all done through automation.
Thanks!
I am attempting to automate the selection of a link on a webpage (that has many links listed).
The example I provided shows just one state (Alabma). My Access form will state which State is required. The user will then click a button that will go to the site, find the State in the list and then go to that particular State's website. I need to figure out how to get the hyperlink of the state and click on it.
So my question is this... How would I code VBA to to find a specific state, in this case Alabama, and click on the hyperlink. The source code of the webpage, for just this Alabama example, is as follows:
<TR valign=center align=left>
<TD><IMG src=/images/pscovl1.gif hspace=10 alt=*>
<A href=https://ecf.alnd.uscourts.gov/ class=linktxt>
Alabama Northern District Court </A> - <font size="1" color="#800517"><b>CM/ECF-
</TD></TR>
How would I programmatically find the "<A href=https://ecf.alnd.uscourts.gov/ class=linktxt>" and click on the link?
I do not want the user to manually click on it - I'm trying to get it all done through automation.
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
jjafferr,
Hey, thanks for coming in on this Q.
I was hoping an Expert with more Web experience than I would chime in.
;-)
JeffCoachman
Hey, thanks for coming in on this Q.
I was hoping an Expert with more Web experience than I would chime in.
;-)
JeffCoachman
ASKER
Thank you! I just had to change the code slightly.
'copy the IE page source to the variable vBody
vBody = ie.Document.Body.innerHTML
'find the 1st occurance of Court name. in the Form this control is named txt_CourtName
vnumber1 = InStr(vBody, Me.Company)
'now read backwords, and find out where does '", "")
'Now Court_Link has the link, let's see if it is exactly what we want:
'MsgBox "+" & Court_Link & "+" 'the reason I added the + on both ends, is so that we can see if there are extra spaces too, to trim
court_link = Trim(court_link)
'now go to the right court
ie.navigate court_link & "/cgi-bin/login.pl"
'copy the IE page source to the variable vBody
vBody = ie.Document.Body.innerHTML
'find the 1st occurance of Court name. in the Form this control is named txt_CourtName
vnumber1 = InStr(vBody, Me.Company)
'now read backwords, and find out where does '", "")
'Now Court_Link has the link, let's see if it is exactly what we want:
'MsgBox "+" & Court_Link & "+" 'the reason I added the + on both ends, is so that we can see if there are extra spaces too, to trim
court_link = Trim(court_link)
'now go to the right court
ie.navigate court_link & "/cgi-bin/login.pl"
Hi dleads
Well, I am glad you got it working :)
I have a few comments about your changes:
>court_link = Trim(court_link)
The Trim here will delete ALL the empty spaces, not only the last empty space,
thus making your ink not useble, so I recommend:
court_link = RTrim(court_link)
>ie.navigate court_link & "/cgi-bin/login.pl"
^^^^^^^^^^
Although this will work for this particular page, but what about the page of the other courts?
Unless off course it is common for all the courts.
jaffer
ps you are welcome Jeff :)
Well, I am glad you got it working :)
I have a few comments about your changes:
>court_link = Trim(court_link)
The Trim here will delete ALL the empty spaces, not only the last empty space,
thus making your ink not useble, so I recommend:
court_link = RTrim(court_link)
>ie.navigate court_link & "/cgi-bin/login.pl"
^^^^^^^^^^
Although this will work for this particular page, but what about the page of the other courts?
Unless off course it is common for all the courts.
jaffer
ps you are welcome Jeff :)
ASKER
Excellent point about the trim. Thank you.
Yes, the /cbi-bin/login.pl is how you get to the login for all of the courts.
I appreciate your help!
Yes, the /cbi-bin/login.pl is how you get to the login for all of the courts.
I appreciate your help!
If the page is already "Selected", why can't you click it manually.
If you can select the link, then you should be able to get it ino vba, then activate it using the FollowHyperlink Command.
Something like this (asssuming you have a textbox with a valid webpage in it):
Dim hlnk As String
hlnk = Me.txtHL
Application.FollowHyperlin
JeffCoachman