CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2001
    Posts
    16

    Simulating keyboard input.

    Greetings,
    Is there a way to bring up the Excel 2000 (9.0) Print Dialog box using VBA code or simulate the keyboard keystrokes of (Alt+F & Ctrl+P) that could be called with a command button? I've got an Excel VBA application, using Microsoft Common Dialog Control 6.0, that worked before we got a new printer network. Excel's Print Dialog does work with my application and the new network, but I'd like to bring it up with a command button.
    Thanks,
    Ken


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Simulating keyboard input.

    You can use the SendKeys command to send keys to the active window.

    SendKeys "%F", false ' sends ctlr + F



    I don't know the sign for ALT, but a quick look in the help file should clear that out.

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    May 2001
    Location
    Canada
    Posts
    182

    Re: Simulating keyboard input.

    SendKeys "%F" 'Sends ALT+F
    SendKeys "^F" 'Sends CTRL+F
    SendKeys "+F" 'Sends SHIFT+F


    Regards,

    Michi
    MCSE, MCDBA

  4. #4
    Join Date
    Mar 2001
    Posts
    16

    Re: Simulating keyboard input.

    Thanks for the replies, however, it doesn't' work the way I was hopping for (nothing too unusual about that). I can get the File menu to drop down (ALT+F), but no action on the next SendKeys "^P",False. Again, what I'm really after is direct access to Excel's Print Dialog Box.
    Thanks,
    Ken



  5. #5
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Simulating keyboard input.

    Do not SendKeys Alt+F, Only use

    SendKeys "^P"


  6. #6
    Join Date
    Mar 2001
    Posts
    16

    Re: Simulating keyboard input.

    Ctrl+P does work, from the keyboard. What I've got is a form with the command button over the worksheet I'm working on. When I click the command button, calling the sub with other code and SendKeys "^P", False, the form still has the focus. I get the mouse hourglass (only over the form), but no Excel Print Dialog Box. It seem as if I need to set the focus back to the worksheet, before SendKeys. Anyone know how to do this? I can't find any method in my books that does this (so far).
    Thanks,
    Ken



  7. #7
    Join Date
    Mar 2001
    Posts
    16

    Re: Simulating keyboard input.

    A slight variation is what worked - SendKeys "{^}P", False
    Thanks,
    Ken


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured