+ Reply to Thread
Results 1 to 3 of 3

SendKeys problem

  1. #1
    Zakynthos
    Guest

    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. #2
    K Dales
    Guest

    RE: 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. #3
    Jim Rech
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    | 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1