Brad Sims
asked on
SendKeys and VBA
I need an alternate way to search through a webpage for a hyperlink and have it selected. My current macro is using the SendKeys command. The issue is, the links are to reports which are sometimes deleted. Meaning, I had the SendKeys command set to tab 15 times to a certain report, but one was deleted this morning so I have to change the Macro.
I've read some of the other posts about SendKeys being unreliable, but what is the alternative?
The link I'm searching for is simply named "Reports".
I've read some of the other posts about SendKeys being unreliable, but what is the alternative?
The link I'm searching for is simply named "Reports".
ASKER
Code and screenshot of the report link is attached. You are correct, it's the actual text displayed in the browser.
I thought about using SendKeys to make the search function in IE appear but I wasn't sure how that would work. There would also have to be more code since half the company is on IE7 and the other half is on IE8.
I thought about using SendKeys to make the search function in IE appear but I wasn't sure how that would work. There would also have to be more code since half the company is on IE7 and the other half is on IE8.
Sub Call_Report()
Dim browser As Object
Dim uname As String
Dim pword As String
Set browser = CreateObject("InternetExplorer.Application")
With browser
browser.Navigate ("http://servicecenter.companyx.com/")
.StatusBar = False
.Toolbar = False
.Visible = True
.Resizable = False
.AddressBar = True
uname = "cservice"
pword = "password"
nline = "{TAB}"
pass = "{ENTER}"
Application.Wait Now + TimeValue("00:00:04")
SendKeys uname, True
SendKeys nline, True
SendKeys pword, True
SendKeys nline, True
SendKeys pass, True
Application.Wait Now + TimeValue("00:00:20")
For i = 1 To 31
SendKeys nline, True
Next i
SendKeys pass, True
Report-Link.jpg
Ok John. With the page opened in IE, from the toolbar up top, select View-Source. Save the resulting file and attach it to your next post. Do not use the right click option to get the source. Thanks
ASKER
Of course I can't get to it now. They are doing maintenance on our DB until 3pm EST. I will have posted as soon as it's available.
No problem.
ASKER
Ok, another issue. I told my boss I was working on this and he informed me I cannot post the code on here. (He doesn't understand what EE is and how it works).
I was able to find the part of the code that references the reports page, but it's written in JavaScript. Does that make a difference?
<input type="hidden" name="Reports" value="../../Home/Controll er/LaunchR eportNet.a spx?" />
I was able to find the part of the code that references the reports page, but it's written in JavaScript. Does that make a difference?
<input type="hidden" name="Reports" value="../../Home/Controll
Well... Without your source I cannot test anything. Here is some air code that you can try. In any case, using SendKeys is like hopping on one foot as opposed to walking. Ask your boss if you would be allowed to email the source privately. Just Find/Replace any information that is confidential.
Try this code as it may work as is. Note that I commented out some of your code and added a few alternative lines.
Tom
Try this code as it may work as is. Note that I commented out some of your code and added a few alternative lines.
Tom
Sub Call_Report()
Dim browser As Object
Dim uname As String
Dim pword As String
Set browser = CreateObject("InternetExplorer.Application")
With browser
browser.Navigate ("http://servicecenter.companyx.com/")
.StatusBar = False
.Toolbar = False
.Visible = True
.Resizable = False
.AddressBar = True
uname = "cservice"
pword = "password"
nline = "{TAB}"
pass = "{ENTER}"
'Application.Wait Now + TimeValue("00:00:04")
Do Until browser.readystate > 3: Loop
SendKeys uname, True
SendKeys nline, True
SendKeys pword, True
SendKeys nline, True
SendKeys pass, True
'Application.Wait Now + TimeValue("00:00:20")
Do Until browser.readystate > 3: Loop
'For i = 1 To 31
' SendKeys nline, True
'Next i
'
'SendKeys pass, True
Dim Element As Object
For Each Element In browser.document.getelementsbyname("Reports")
If InStr(Element.innerhtml, "Controller/LaunchReportNet.aspx") Then
Element.Click
End If
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Apologies, my work laptop died on me so I've been busy getting everything back in order. Will work on this Monday and let you know.
<i>The link I'm searching for is simply named "Reports".</i>
I am assuming that you are defining name to be the actual text that is displayed in the browser. Correct?
Have a nice day. Tom