View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
PaulD PaulD is offline
external usenet poster
 
Posts: 92
Default Interaction with Internet Explorer


"Ron" wrote in message
10.130...
: 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