Results 1 to 6 of 6
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    SendKeys (XL97; SR-2)

    I'm trying to utilize the "SendKeys" statement in vba inconjunction with WinZip. My ultimate goal is to create individual zip files for each spreadsheet in a laundry list and at some point unzip them.

    My problem is that I can not get the "SendKeys" statement to work. As an example I have tried to write code that simply closes and exits XL .

    Sample Code:
    Sub CloseItDown()
    Application.SendKeys ("%fx")
    End Sub


    Any assistance would truly be appreciated.

    John

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: SendKeys (XL97; SR-2)

    John,

    You do not need SendKeys to exit XL, just use Application.Quit

    Andrew C

  3. #3
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SendKeys (XL97; SR-2)

    Andrew,

    I was making a point that there seems to be a problem with functionalily of "SendKeys" . If I can not pass a simple keystroke such as ALT-f then an x to exit the program I must be doing something wrong or the functionality does not work the way it should.

    John

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: SendKeys (XL97; SR-2)

    John,

    Sorry for misunderstanding your problem.

    One problem with SendKeys is that the keystrokes you want to send are not actually sent until VBA has finished running it's code so this may be a factor.

    Andrew C

  5. #5
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SendKeys (XL97; SR-2)

    Andrew,

    I did some searching on MSKB and found a document (Q160219) which address what you mentioned. The solution was to use the code:

    Application.SendKeys Keys:="(%fx"), Wait:=True


    This also does not work.

    John

  6. #6
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: SendKeys (XL97; SR-2)

    John,

    There is one other important factor in using SendKeys, the window to which you are sending the keystrokes must have focus.

    Your code to quit XL should work if you run it from an Excel workbook, when Excel itself has focus, and VBA

    Andrew C

Posting Permissions

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