Interaction with Internet Explorer

R

Ron

Hi guys,

If I wanted to send say 10 or so numerical values from excel to 10 or so
input boxes in a web page how would I go about it?

Is it possible to do this through excel and maybe a custom form, or would
it be more efficient with a stand alone VB program?

The values will change in excel every once in a while, and need to be
copy/pasted into the relevant input boxes in the web page. These input
boxes in the web page stay constant in position, is it possible through
screen position?

Regards,

Ron
 
P

PaulD

: Hi guys,
:
: If I wanted to send say 10 or so numerical values from excel to 10 or so
: input boxes in a web page how would I go about it?
:
: Is it possible to do this through excel and maybe a custom form, or would
: it be more efficient with a stand alone VB program?
:
: The values will change in excel every once in a while, and need to be
: copy/pasted into the relevant input boxes in the web page. These input
: boxes in the web page stay constant in position, is it possible through
: screen position?
:
: Regards,
:
: Ron

Does the webpage allow tabs to cycle through the fields? Could you use
sendkeys?
Paul D
 
R

Ron

Does the webpage allow tabs to cycle through the fields? Could you use
sendkeys?
Paul D



Hi Paul,

Yes the web page will tab through the input boxes, and I have thought about
the sendkeys method but am unsure of the syntax as I've not yet used this
method.

I'm still learning VBA, so any examples would be more than helpful.

Thanks,

Ron
 
P

PaulD

:
: >
: > Does the webpage allow tabs to cycle through the fields? Could you use
: > sendkeys?
: > Paul D
: >
:
: Hi Paul,
:
: Yes the web page will tab through the input boxes, and I have thought
about
: the sendkeys method but am unsure of the syntax as I've not yet used this
: method.
:
: I'm still learning VBA, so any examples would be more than helpful.
:
: Thanks,
:
: Ron
:

Ron,
Here is an example from the help file if using sendkeys from Excel

SendKeys Statement Example
This example uses the Shell function to run the Calculator application
included with Microsoft Windows. It uses the SendKeys statement to send
keystrokes to add some numbers, and then quit the Calculator. (To see the
example, paste it into a procedure, then run the procedure. Because
AppActivate changes the focus to the Calculator application, you can't
single step through the code.). On the Macintosh, use a Macintosh
application that accepts keyboard input instead of the Windows Calculator.
Dim ReturnValue, I
ReturnValue = Shell("CALC.EXE", 1) ' Run Calculator.
AppActivate ReturnValue ' Activate the Calculator.
For I = 1 To 100 ' Set up counting loop.
SendKeys I & "{+}", True ' Send keystrokes to Calculator
Next I ' to add each value of I.
SendKeys "=", True ' Get grand total.
SendKeys "%{F4}", True ' Send ALT+F4 to close Calculator.

If you want to try using sendkeys from a script, here is an old script I
used to use to bypass the outlook security (not needed with 2003). You
would need to make a reference to Excel and read the data from the
spreadsheet then use sendkeys to fill out the form.

i=0
Set fso = CreateObject ("WScript.Shell")
While fso.AppActivate ("Microsoft Outlook") = FALSE
wscript.sleep 300
i = i + 1
if i = 15 then wscript.quit
Wend
fso.SendKeys "a",True
fso.SendKeys "{TAB}{TAB}",True
fso.SendKeys "{Enter}",True
Set fso=Nothing

Paul D
 
R

Ron

Hi Paul (and anyone else who can help)

I tried the example from the help file and it ran fine, however when I
changed it somewhat it seems to fail.

This is what I tried..

Sub SendkeysTest()
Dim proggy
proggy = Shell("C:\Program Files\Internet Explorer\iexplore.exe", 3)
AppActivate proggy 'THIS IS WHERE IT FAILS
SendKeys "{TAB}"
SendKeys "www.google.com"
SendKeys "~"
End Sub


This opens an IE window ok, but then the window doesn't get focus. When
the line 'AppActivate proggy' comes round the code gives an error.

The sendkeys lines actually work fine, but what they seem to be doing is
sending the keys to the vbe itself, because the 'www.google.com' gets
inserted on the line where the insertion point is in the code.

Thanks for the help so far.

Ron
 
P

PaulD

: Hi Paul (and anyone else who can help)
:
<snip>
: Sub SendkeysTest()
: Dim proggy
: proggy = Shell("C:\Program Files\Internet Explorer\iexplore.exe", 3)
: AppActivate proggy 'THIS IS WHERE IT FAILS
: SendKeys "{TAB}"
: SendKeys "www.google.com"
: SendKeys "~"
: End Sub
:
:
: This opens an IE window ok, but then the window doesn't get focus. When
: the line 'AppActivate proggy' comes round the code gives an error.
<snip>

Ron,
The problem here is the code is much faster than the computer. When you
start your shell to IE, the program has not loaded by the time you are
trying to activate it and this causes an error. You have to slow down the
code a bit. I'm sure there are much more resourceful ways of doing this but
a 'brute force' method is creating a wait command
Application.Wait (Now + TimeValue("0:00:5"))
this will make the code pause 5 seconds while waiting for the IE to load.
Keep in mind you can have the same problem with sendkeys. This worked on my
machine
Sub SendkeysTest()
Dim proggy As Long
proggy = Shell("C:\Program Files\Internet Explorer\iexplore.exe", 3)
Application.Wait (Now + TimeValue("0:00:5"))
AppActivate proggy 'THIS IS WHERE IT FAILS
SendKeys "{TAB}"
SendKeys "www.google.com"
Application.Wait (Now + TimeValue("0:00:1"))
SendKeys "~"
End Sub

Paul
 
R

Ron

Ron,
The problem here is the code is much faster than the computer. When
you start your shell to IE, the program has not loaded by the time you
are trying to activate it and this causes an error. You have to slow
down the code a bit.



Thanks Paul, works ok on mine also. However when/if I actually use this I
want to have the IE window already open, logged in to the web page and then
I will manually bring up the input box/boxes. How do I tell the code which
specific App to activate.

When I get to the ....proggy = Shell("C:\Program Files\....line of code it
opens a fresh blank IE window. This is not what I want. I want it to
activate an existing version of IE.

Any suggestions appreciated.

Thanks again Paul.

Ron
 
R

Ron

Hi again Paul,


A bit of research shows that AppActivate "Google" or even AppActivate
"Goo" will give the IE window with the google page focus.

Thanks for all the help Paul.


Ron
 
P

PaulD

: Hi again Paul,
:
: A bit of research shows that AppActivate "Google" or even AppActivate
: "Goo" will give the IE window with the google page focus.
:
: Thanks for all the help Paul.
:
: Ron

You're welcome. And for anyone else following this thread
http://www.freevbcode.com/ShowCode.asp?ID=526
has some code for how to "Activate an App by a Partial Window Title"
Paul D
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top