Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    Jan 2001
    Location
    Karlsruhe, Germany
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sending keystrokes to another window (VBA Word 2002)

    Hi,
    How can I send keystrokes to a (non-office) application running in another window and then come back to the Word window? I have seen some (password-protected) macros do it, so I know it is possible.

    Thanks for any help,

    Ed Colaianni
    Karlsruhe, Germany

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Sending keystrokes to another window (VBA Word 2002)

    Will you start the other application from VBA, or will it already be active?

  3. #3
    Lounger
    Join Date
    Jan 2001
    Location
    Karlsruhe, Germany
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sending keystrokes to another window (VBA Word 2002)

    I was planning on having a single instance of the other application open in another window, there will be something unique in the title bar I can look for to identify it.
    Ed Colaianni
    Karlsruhe, Germany

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Sending keystrokes to another window (VBA Word 2002)

    You could try

    AppActivate "Unique title"
    SendKeys "Test{Enter}"

    Look up SendKeys in the VBA help for the special key codes you can use.

  5. #5
    Lounger
    Join Date
    Jan 2001
    Location
    Karlsruhe, Germany
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sending keystrokes to another window (VBA Word 2002)

    This is great, thank you so much: it actually goes to the other window and sends keystrokes to it!

    Some points in case anyone else tries this:

    The string in AppActivate must be the beginning of the title in the window title bar. If not unique, then you get one at random.
    You can use AppActivate to get back to Word after you send the keystrokes, but if you come back too soon, the keystrokes land in the word document. I was able to avoid that with Sendkeys "xxxx", TRUE where true is the boolean for "wait" described in the Help.
    I was not able test this in the VBA window where I am used to testing everything else (wasted lots of time trying!): I had to go to the Word window and execute the macro from there!
    If the App is not open already, you can open it with shell (see VBA help)
    If you opened the App with shell, save the value returned and use it in AppActivate instead of the string. That way you are sure to get the right window

    Ed

Posting Permissions

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