+ Reply to Thread
Results 1 to 6 of 6

Programmatically add "worksheet activate" event

  1. #1
    Registered User
    Join Date
    02-24-2010
    Location
    Catalonia
    MS-Off Ver
    Excel 2002
    Posts
    13

    Programmatically add "worksheet activate" event

    Hi there,

    Is there any way to add a "worksheet activate" event to a sheet by using VBA code?

    I have a macro in which I create a new sheet and want to add a "worksheet activate" event to it.

    Thanks in advance for any help!

    js
    Last edited by js8765; 03-05-2010 at 10:56 AM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,015

    Re: Programmatically add "worksheet activate" event

    Is the event code the same for each sheet that you add?
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Programmatically add "worksheet activate" event

    This is probably worth a look: http://www.cpearson.com/excel/vbe.aspx

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  4. #4
    Registered User
    Join Date
    02-24-2010
    Location
    Catalonia
    MS-Off Ver
    Excel 2002
    Posts
    13

    Re: Programmatically add "worksheet activate" event

    Hi again,

    Well...the event code will be the same for each sheet I create using the sub.

    Basically the sub has to add one sheet and then add the event code just to that sheet...

    Cheers,

    js

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,015

    Re: Programmatically add "worksheet activate" event

    If you use the Workbook_SheetActivate event instead it will fire for all sheets in the workbook but you can tell it not to do anything if the sheet has a particular name. That means that you wouldn't need to add any code to the sheets as you create them - the event will work for them automatically.

  6. #6
    Registered User
    Join Date
    02-24-2010
    Location
    Catalonia
    MS-Off Ver
    Excel 2002
    Posts
    13

    Re: Programmatically add "worksheet activate" event

    OK.

    Thank you both for the ideas. I found some code that should do the trick in the link Dom sent under the section "Adding A Procedure To A Module"

    Cheers,

    js

+ 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