• On activating a Workbook . . .

    Author
    Topic
    #2531766

    I know how to run a procedure when a Worksheet is activated . . .

    in the Worksheet code:

    Private Sub Worksheet_Activate()

            [Some code]

    End Sub

    But how can I run a procedure when a Workbook is activated ?

    I would also like to run a procedure when the Workbook is de-activated (loses focus) but I am not sure that’s possible – I can cope without that.

    Thanks, Martin

    • This topic was modified 1 month, 2 weeks ago by WSMartinM.
    Viewing 3 reply threads
    Author
    Replies
    • #2531768

      PS I tried the following, in the Workbook code, but it did nothing at all !

      Private Sub Workbook_WindowActivate(ByVal Wn As Excel.Window)

          [Some code]

      End Sub

    • #2531769

      PS I tried the following, in the Workbook code, but it did nothing at all !

      Private Sub Workbook_WindowActivate(ByVal Wn As Excel.Window)

      [and  Private Sub Workbook_WindowActivate(ByVal Wn As Window) ]

          [Some code]

      End Sub

      • #2531849

        In ThisWorkbook (under “Microsoft Excel Object”, not in a macro code module) use

        Private Sub Workbook_Activate()
          <...your code goes here...>
        End Sub
    • #2532054

      Yes, that works, thanks, but only when opening the Workbook, not when, for instance, switching from another Workbook.

      I could use the Auto-Open macro if I wanted it to run on opening.

      What am I missing ?

    • #2532101

      <p style=”text-align: left;”>Thanks – sorted now.
      For some reason Private Sub Workbook_Activate() doesn’t run when I switch from one Workbook to another, but Private Sub Workbook_WindowActivate(ByVal Wn As Window) does run.</p>

    Viewing 3 reply threads
    Reply To: On activating a Workbook . . .

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: