+ Reply to Thread
Results 1 to 5 of 5

SendKeys won't fire on Workbook_Deactivate or Workbook_BeforeClose

  1. #1
    Registered User
    Join Date
    11-20-2012
    Location
    Oklahoma City, OK
    MS-Off Ver
    2010
    Posts
    3

    SendKeys won't fire on Workbook_Deactivate or Workbook_BeforeClose

    I have a script using 'Workbook_Activate' that performs a few actions when the workbook opens, among them is to minimize the Ribbon using SendKeys. (I only want the Ribbon minimized, not hidden, that's why SendKeys.) I have another script using 'Workbook_Deactivate' that reverses these actions, but the SendKeys line won't run. It does'nt lock up, it just doesn't restore the Ribbon. Any ideas would be appreciated. (BTW: all the other commands work fine both opening and closing and yes, I've tried 'Workbook_BeforeClose' with the same results.) Heres my script:

    Option Explicit
    ______________________________________________

    Private Sub Workbook_Activate()
    Application.ScreenUpdating = False
    Worksheets("Class Scores").Activate
    ActiveWindow.WindowState = xlMaximized
    Application.WindowState = xlMaximized
    ActiveWindow.ScrollRow = 1
    ActiveWindow.ScrollColumn = 1
    Range("Y5").Select
    Application.DisplayFormulaBar = False
    If Application.CommandBars.Item("Ribbon").Height > 60 Then
    Application.SendKeys ("^{F1}")
    Else: GoTo Finish:
    End If
    Finish:
    Application.ScreenUpdating = True
    Call ToggleCutCopyAndPaste(False)
    End Sub
    _______________________________________________________

    Private Sub Workbook_Deactivate()
    Application.SendKeys ("^{F1}")
    Application.DisplayFormulaBar = True
    Call ToggleCutCopyAndPaste(True)
    End Sub

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: SendKeys won't fire on Workbook_Deactivate or Workbook_BeforeClose

    Try inserting:

    Please Login or Register  to view this content.
    immediately after the SendKeys
    Gary's Student

  3. #3
    Registered User
    Join Date
    11-20-2012
    Location
    Oklahoma City, OK
    MS-Off Ver
    2010
    Posts
    3

    Re: SendKeys won't fire on Workbook_Deactivate or Workbook_BeforeClose

    Thanks Jakobshavn...that works fine when closing the workbook! However, when switching between workbooks, the other actions work fine, but the ribbon won't restore. You did so good with your first suggestion, how about taking a shot at this one

    NEW INFO: Interesting...if I switch between this workbook and another xlsx file, it works fine. But, if I open a new workbook while this one is open, it doesn't toggle the ribbon when switching between those two books.
    Last edited by xzlaatc; 11-26-2012 at 01:36 PM.

  4. #4
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: SendKeys won't fire on Workbook_Deactivate or Workbook_BeforeClose

    Because CNTRL-F1 is a toggle, if it is issued twice, it looks like its not working.

    I suggest you place MsgBoxes before and after each SendKeys to make sure we understand exactly what is happening.

  5. #5
    Registered User
    Join Date
    11-20-2012
    Location
    Oklahoma City, OK
    MS-Off Ver
    2010
    Posts
    3

    Re: SendKeys won't fire on Workbook_Deactivate or Workbook_BeforeClose

    I'll give it a try...thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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