Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 115
Default SendKeys problem

I'm using SendKeys to access various parts of a company intranet, input
usernames/passwords, move through various menus etc.

Each subroutine works fine in itself but when I try to run them all
together, I keep getting errors at the "AppActivate .....(2nd window)". But
when run separately, this (second) macro works quite OK.

I've tried to solve the problem by using:

Appactivate "Microsoft Excel"

at the end of the first subroutine in order to 'return' to the Excel window,
but this doesn't seem to work either.

What's causing the problem and how do I solve it?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default SendKeys problem

Try using the True parameter at the end of the statement, e.g.:
AppActivate "Microsoft Excel", True
AppActivate "OtherApp", True
(this forces VBA to wait until the calling app (your VBA routine in Excel)
has the focus back before it activates the next one - sometimes the timing
makes a difference on whether the app is ready to be activated yet. In
practice I have found I need to figure this out by trial and error.
--
- K Dales


"Zakynthos" wrote:

I'm using SendKeys to access various parts of a company intranet, input
usernames/passwords, move through various menus etc.

Each subroutine works fine in itself but when I try to run them all
together, I keep getting errors at the "AppActivate .....(2nd window)". But
when run separately, this (second) macro works quite OK.

I've tried to solve the problem by using:

Appactivate "Microsoft Excel"

at the end of the first subroutine in order to 'return' to the Excel window,
but this doesn't seem to work either.

What's causing the problem and how do I solve it?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default SendKeys problem

Sendkeys is difficult to work with because the keys are not actually
executed until there is nothing else to do in the macro.

So with this:

Sub Demo()
Application.SendKeys "Abcd", True
Application.SendKeys "{Down}", True
EnterNumber
EnterNumber
EnterNumber
End Sub

Sub EnterNumber()
ActiveCell.Value = 123
ActiveCell.Offset(1).Select
End Sub

the "Abcd" is the last item entered by the macro even though it's first in
the macro. I don't know whether this is a factor in what you're doing so
just FYI. A DoEvents may help here. If you insert DoEvents after the
second SendKeys above Abcd is entered first. Even so Sendkeys is never a
really reliable answer.

--
Jim
"Zakynthos" wrote in message
...
| I'm using SendKeys to access various parts of a company intranet, input
| usernames/passwords, move through various menus etc.
|
| Each subroutine works fine in itself but when I try to run them all
| together, I keep getting errors at the "AppActivate .....(2nd window)".
But
| when run separately, this (second) macro works quite OK.
|
| I've tried to solve the problem by using:
|
| Appactivate "Microsoft Excel"
|
| at the end of the first subroutine in order to 'return' to the Excel
window,
| but this doesn't seem to work either.
|
| What's causing the problem and how do I solve it?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SendKeys syntax problem VBAvirgin New Users to Excel 2 January 4th 06 04:42 PM
sendkeys problem jmoffat[_17_] Excel Programming 1 June 17th 05 05:30 PM
sendkeys problem for telnet mike Excel Programming 1 June 15th 05 02:12 PM
SendKeys problem Rod Armour Excel Programming 3 January 23rd 04 10:44 PM
SendKeys and Path Problem rdcord Excel Programming 3 September 11th 03 06:12 PM


All times are GMT +1. The time now is 11:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"