ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Programally add a Macro to Multiple Sheets (https://www.excelbanter.com/excel-programming/400425-programally-add-macro-multiple-sheets.html)

Sol

Programally add a Macro to Multiple Sheets
 
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)?

FSt1

Programally add a Macro to Multiple Sheets
 
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.

regards
FSt1

"Sol" wrote:

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)?


SteveM

Programally add a Macro to Multiple Sheets
 
On Nov 1, 12:24 pm, FSt1 wrote:
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



regards
FSt1

"Sol" wrote:
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)?




FSt1

Programally add a Macro to Multiple Sheets
 
hi
see my reply to the post just before yours.
http://cpearson.com/excel/vbe.htm

Regards
FSt1

"FSt1" wrote:

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.

regards
FSt1

"Sol" wrote:

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)?


Gord Dibben

Programally add a Macro to Multiple Sheets
 
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

On Thu, 1 Nov 2007 09:19:02 -0700, Sol wrote:

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)?




All times are GMT +1. The time now is 01:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com