Josh Hazel
05-09-2008, 02:46 AM
How can I send text to another application through an Excel VBA sub routine, particularly Internet Explorer?
For example... press a button in excel to open internet explorer (new window) and goto www.google.com and type in "test" in the search field.
I was able to open the webpage with Shell ("iexplorer location" "website") but when i try using Sendkeys "text", it doesnt seem to work.
I also cant seem to figure out how to activate a specific IE window... if I have 2 IE windows open one is at google and the other is at yahoo... im not sure how to use an appactivate (or similar) to distinguish the two...
ibnerafiq
05-09-2008, 04:07 AM
First you should add referneces of Microsoft Internet Controls and Microsoft Html object Library.
If the brwoser is already open then you can run following code to activate google site.And manipulation of vba and html you should know html Dom(http://www.w3schools.com/HTMLDOM/default.asp) and webpage inspector to know html behind the google page.
Sub IESelection()
Public IEs As SHDocVw.ShellWindows
Public IE As SHDocVw.InternetExplorer
Dim Doc As HTMLDocument
Set IE = New SHDocVw.InternetExplorer
Set IEs = New SHDocVw.ShellWindows
For Each IE In IEs
If IE.LocationURL = "http://google.com" Then
IE.Visible = True
Set IE = IE
Exit For
End If
Next
End Sub
Colin Legg
05-09-2008, 04:37 AM
There is also a slight code variation found in the code library section of our Knowledge Base:
http://www.xtremevbtalk.com/showthread.php?t=247384
Josh Hazel
05-09-2008, 10:24 PM
Thanks, I was able to come up with a solution to solve this problem - it seems to
My work intranet has the following html code on their timesheet...
onChange="logTypeChange()">
<OPTION value="1" selected>Log In</OPTION>
<OPTION value="2">Lunch</OPTION>
<OPTION value="3">Break</OPTION>
<OPTION value="4">Downtime</OPTION>
<OPTION value="5">Meeting</OPTION>
<OPTION value="6">Project</OPTION>
<OPTION value="7">Support</OPTION>
<OPTION value="8">Training</OPTION>
<OPTION value="9">Log Out</OPTION>
<OPTION value="10">System Aux</OPTION>
<OPTION value="11">Other</OPTION>
<OPTION value="12">New Hire Training</OPTION>
<OPTION value="13">Uptraining</OPTION>
It seems easy enough to send text or a click a button from VBA to IE, but how would I go about selecting one of these options?
Without access from home, I am taking a stab at this ... I am curious if anyone knows if something like... objIE.Document.All("logtypechange").Value = "1" would work (just changing the # value to the log selected)
NateO
05-11-2008, 12:50 PM
Hello,
Assuming that's a drop-down with fixed options, you do it the same way you'd pass a value to a text box, except you pass one of the acceptable values, e.g., .prov.value:
http://www.xtremevbtalk.com/showthread.php?p=973120
You just need to figure out the name of the control, which you didn't include in your post and proceed from there. ;)
You just need to figure out the name of the control, which you didn't include in your post and proceed from there.
just wondering.. do you know of any way or addon that would help distinguish these control names? I have a company page that's way too complicated for me to figure out what the names of each elements :mad: