Programally add a Macro to Multiple Sheets

G

Guest

Hello everyone,

I've been runnning in a problem with a workbook I'm trying to make. This
workbook has a worksheet, that after filled with some datas a macro will
create "n" new worksheets on this same workbook.

These new worksheets all share some macros (doubleclick, OnChange, etc) but
not the original sheet. How can I , when I create the sheet via macro, add a
group of macros to it. Or is there a way to make a macro be accessible from
all Worksheets (but not all WORKBOOKS, mind you, only this one)?
 
S

SteveM

hi
what you want can be done but you didn't give enought info for me to help.
see this site.http://cpearson.com/excel/vbe.htm
macros that write macros. also move, delete, add ect.
Why don't you just create a template sheet first with the Macros in it
and copy that?

It's not clear to me, but if you want to copy the data from the
original sheet then just copy the sheet content and paste as formulas
or values (whatever makes sense) to the template. You could delete
the template sheet at the end of the process if you wanted to.

KISS?

SteveM
 
G

Gord Dibben

You can place sheet events into Thisworkbook module that will run on all sheets,
existing or new.

Using that method you don't need event code in each individual sheet.

If you don't want the code to run on the particular sheet exclude it.

Private Sub Workbook_SheetBeforeDoubleClick _
(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)

If ActiveSheet.Name = "Sheet1" Then Exit Sub

do your stuff

End Sub


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top