+ Reply to Thread
Results 1 to 4 of 4

How do I write VB to run Macro when sheet selected?

  1. #1
    JR_06062005
    Guest

    How do I write VB to run Macro when sheet selected?

    I am trying to write VB code to cause a Macro to run when a particular
    worksheet is selected. How do I write this code and where do I place it?

  2. #2
    mark
    Guest

    RE: How do I write VB to run Macro when sheet selected?

    > I am trying to write VB code to cause a Macro to run when a particular
    > worksheet is selected. How do I write this code and where do I place it?


    The code is the same as any other VB code... whatever you need it to do.

    You place it in the worksheet's code mudule...

    In the VB window, press View-Project Explorer
    Double click the sheet that you want the code to work with
    Use the drop box in the upper left and select 'Worksheet'
    Use the drop box in the upper right to select 'Activate'

    When you do that, a subroutine will come up that looks like this:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    End Sub

    Each time the sheet is activated, that code will run.



  3. #3
    Tom Ogilvy
    Guest

    Re: How do I write VB to run Macro when sheet selected?

    Think Mark copied the wrong event declaration:

    Private Sub Worksheet_Activate()

    End Sub

    is what he describes.

    --
    Regards,
    Tom Ogilvy


    "mark" <[email protected]> wrote in message
    news:[email protected]...
    > > I am trying to write VB code to cause a Macro to run when a particular
    > > worksheet is selected. How do I write this code and where do I place

    it?
    >
    > The code is the same as any other VB code... whatever you need it to do.
    >
    > You place it in the worksheet's code mudule...
    >
    > In the VB window, press View-Project Explorer
    > Double click the sheet that you want the code to work with
    > Use the drop box in the upper left and select 'Worksheet'
    > Use the drop box in the upper right to select 'Activate'
    >
    > When you do that, a subroutine will come up that looks like this:
    >
    > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    >
    > End Sub
    >
    > Each time the sheet is activated, that code will run.
    >
    >




  4. #4
    mark
    Guest

    Re: How do I write VB to run Macro when sheet selected?

    > Think Mark copied the wrong event declaration:


    Yep, I sure did.

    Thanks for the catch.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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