How to create a dynamic event procedure?

alanw64

New Member
Joined
Jun 1, 2009
Messages
6
Ok, I might be making this harder than it seems, but after multiple searches here and elsewhere, I can't seem to find the answer.

I have a macro that will add multiple worksheets. When the worksheet is added, is there a way to dynamically create code inside the Worksheet_Activate event procedure? The macro dialogbox will remain open (non-modal form), and ideally, if the user switches to another worksheet, I would like the macro dialogbox to know about it via the Worksheet_Activate event. Is that possible?

Basically, I would like my macro to create the following code for every worksheet that gets added:

Private Sub Worksheet_Activate()
Call MyMacroEvent
End Sub

I started reading about the VBA extensibility and the VBE, but I'm not sure if that's what I need or not. Hopefully there's an easier solution!

Thank you for any input,
Alan
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hi Alan

Are you familiar with the Workbook_SheetActivate(ByVal Sh As Object) event? It will trigger when ever you activate any sheet (In ThisWorkbook module). Would this be viable?
 
Upvote 0
You can also replace
Rich (BB code):
    Worksheets.Add

with
Rich (BB code):
    Worksheets("HiddenSheet").Visible = True
    Worksheets("HiddenSheet").Copy Worksheets("HiddenSheet")
    Worksheets("HiddenSheet").Visible = 2 ' hide

where HiddenSheet is a worksheet that contains some event procedures.
 
Upvote 0
EducatedFool and VoG --

Excellent suggestions, too -- thank you very much!

"...ask and ye shall receive...!" :)
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,841
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top