Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default run all worksheet macros

I have a workbook with 35 worksheets, each with a different macro.

How can I create a workbook level macro to run the specific macro tied
to each of the 35 worksheets?

Thanks.

I have checked out some previous postings, but they all seem to apply
a single macro against multiple sheets, but I need to launch a macro
tied to each of 35 sheets.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 791
Default run all worksheet macros

First create a list of the Macros you have attach the list to a dropdown box,
and set the on change event to execute a Case statement, on each case you
will have a call for the corresponding macro to be executed.

Michael Arch.


"Old Fossil Bama" wrote:

I have a workbook with 35 worksheets, each with a different macro.

How can I create a workbook level macro to run the specific macro tied
to each of the 35 worksheets?

Thanks.

I have checked out some previous postings, but they all seem to apply
a single macro against multiple sheets, but I need to launch a macro
tied to each of 35 sheets.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default run all worksheet macros

One way, but a little tedious:

Sub CallSheetMacros()
' assumes macro is called Macro1 in each sheet
Sheet1.Macro1
Sheet2.Macro1
Sheet3.Macro1
:
:
Sheet3.Macro1
End Sub

Sub test()
' more scalable ... still assumes macro is called Macro1 in each sheet
For Each sht In Sheets
On Error Resume Next
sht.Macro1
On Error GoTo 0
Next
End Sub

Regards

Trevor


"Old Fossil Bama" wrote in message
ups.com...
I have a workbook with 35 worksheets, each with a different macro.

How can I create a workbook level macro to run the specific macro tied
to each of the 35 worksheets?

Thanks.

I have checked out some previous postings, but they all seem to apply
a single macro against multiple sheets, but I need to launch a macro
tied to each of 35 sheets.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default run all worksheet macros

I think that the second suggestion has to be more like:

Sub test()
' more scalable ... still assumes macro is called Macro1 in each sheet
For Each sht In Sheets
On Error Resume Next
application.run sht.codename & ".Macro1"
On Error GoTo 0
Next
End Sub

The error checking may not be required if all the worksheet modules have a
procedure named Macro1.



Trevor Shuttleworth wrote:

One way, but a little tedious:

Sub CallSheetMacros()
' assumes macro is called Macro1 in each sheet
Sheet1.Macro1
Sheet2.Macro1
Sheet3.Macro1
:
:
Sheet3.Macro1
End Sub

Sub test()
' more scalable ... still assumes macro is called Macro1 in each sheet
For Each sht In Sheets
On Error Resume Next
sht.Macro1
On Error GoTo 0
Next
End Sub

Regards

Trevor

"Old Fossil Bama" wrote in message
ups.com...
I have a workbook with 35 worksheets, each with a different macro.

How can I create a workbook level macro to run the specific macro tied
to each of the 35 worksheets?

Thanks.

I have checked out some previous postings, but they all seem to apply
a single macro against multiple sheets, but I need to launch a macro
tied to each of 35 sheets.


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default run all worksheet macros

Or, you should be able to use one macro for all sheets unless there is a lot
of difference for each sheet.
Examples?

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Old Fossil Bama" wrote in message
ups.com...
I have a workbook with 35 worksheets, each with a different macro.

How can I create a workbook level macro to run the specific macro tied
to each of the 35 worksheets?

Thanks.

I have checked out some previous postings, but they all seem to apply
a single macro against multiple sheets, but I need to launch a macro
tied to each of 35 sheets.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default run all worksheet macros

In a different thread JE McGimpsey showed that this was possible using code
similar to what Trevor showed.

Option Explicit
Sub aa()
Dim sht As Variant 'or As Object
For Each sht In Worksheets
sht.dtest
Next sht
End Sub

It didn't work for me the way Trevor wrote it because I used:
dim sht as worksheet

If I had left sht as an undeclared variant (or declared it as an object or a
variant), it would have worked fine.

Sorry for doubting your code Trevor <bg.

Dave Peterson wrote:

I think that the second suggestion has to be more like:

Sub test()
' more scalable ... still assumes macro is called Macro1 in each sheet
For Each sht In Sheets
On Error Resume Next
application.run sht.codename & ".Macro1"
On Error GoTo 0
Next
End Sub

The error checking may not be required if all the worksheet modules have a
procedure named Macro1.

Trevor Shuttleworth wrote:

One way, but a little tedious:

Sub CallSheetMacros()
' assumes macro is called Macro1 in each sheet
Sheet1.Macro1
Sheet2.Macro1
Sheet3.Macro1
:
:
Sheet3.Macro1
End Sub

Sub test()
' more scalable ... still assumes macro is called Macro1 in each sheet
For Each sht In Sheets
On Error Resume Next
sht.Macro1
On Error GoTo 0
Next
End Sub

Regards

Trevor

"Old Fossil Bama" wrote in message
ups.com...
I have a workbook with 35 worksheets, each with a different macro.

How can I create a workbook level macro to run the specific macro tied
to each of the 35 worksheets?

Thanks.

I have checked out some previous postings, but they all seem to apply
a single macro against multiple sheets, but I need to launch a macro
tied to each of 35 sheets.


--

Dave Peterson


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default run all worksheet macros

Based on this statement:

I have checked out some previous postings, but they all seem to apply
a single macro against multiple sheets, but I need to launch a macro
tied to each of 35 sheets.


I deduce that you have thirty five different macros, even though they may
perform similar operations, one macro cannot be run against all thirty five
sheets. That means that you would have to use a master macro like Trevor
suggested where you call each macro in sequence. Watch the syntax.

"Old Fossil Bama" wrote:

I have a workbook with 35 worksheets, each with a different macro.

How can I create a workbook level macro to run the specific macro tied
to each of the 35 worksheets?

Thanks.

I have checked out some previous postings, but they all seem to apply
a single macro against multiple sheets, but I need to launch a macro
tied to each of 35 sheets.


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default run all worksheet macros

Why do you say "I think that the second suggestion has to be more like:".

I tested the code I provided and it works as presented. What issues do you
envisage ?

Regards

Trevor


"Dave Peterson" wrote in message
...
I think that the second suggestion has to be more like:

Sub test()
' more scalable ... still assumes macro is called Macro1 in each sheet
For Each sht In Sheets
On Error Resume Next
application.run sht.codename & ".Macro1"
On Error GoTo 0
Next
End Sub

The error checking may not be required if all the worksheet modules have a
procedure named Macro1.



Trevor Shuttleworth wrote:

One way, but a little tedious:

Sub CallSheetMacros()
' assumes macro is called Macro1 in each sheet
Sheet1.Macro1
Sheet2.Macro1
Sheet3.Macro1
:
:
Sheet3.Macro1
End Sub

Sub test()
' more scalable ... still assumes macro is called Macro1 in each sheet
For Each sht In Sheets
On Error Resume Next
sht.Macro1
On Error GoTo 0
Next
End Sub

Regards

Trevor

"Old Fossil Bama" wrote in message
ups.com...
I have a workbook with 35 worksheets, each with a different macro.

How can I create a workbook level macro to run the specific macro tied
to each of the 35 worksheets?

Thanks.

I have checked out some previous postings, but they all seem to apply
a single macro against multiple sheets, but I need to launch a macro
tied to each of 35 sheets.


--

Dave Peterson



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default run all worksheet macros

I used:
dim sht as worksheet
and the code failed.



Trevor Shuttleworth wrote:

Why do you say "I think that the second suggestion has to be more like:".

I tested the code I provided and it works as presented. What issues do you
envisage ?

Regards

Trevor

"Dave Peterson" wrote in message
...
I think that the second suggestion has to be more like:

Sub test()
' more scalable ... still assumes macro is called Macro1 in each sheet
For Each sht In Sheets
On Error Resume Next
application.run sht.codename & ".Macro1"
On Error GoTo 0
Next
End Sub

The error checking may not be required if all the worksheet modules have a
procedure named Macro1.



Trevor Shuttleworth wrote:

One way, but a little tedious:

Sub CallSheetMacros()
' assumes macro is called Macro1 in each sheet
Sheet1.Macro1
Sheet2.Macro1
Sheet3.Macro1
:
:
Sheet3.Macro1
End Sub

Sub test()
' more scalable ... still assumes macro is called Macro1 in each sheet
For Each sht In Sheets
On Error Resume Next
sht.Macro1
On Error GoTo 0
Next
End Sub

Regards

Trevor

"Old Fossil Bama" wrote in message
ups.com...
I have a workbook with 35 worksheets, each with a different macro.

How can I create a workbook level macro to run the specific macro tied
to each of the 35 worksheets?

Thanks.

I have checked out some previous postings, but they all seem to apply
a single macro against multiple sheets, but I need to launch a macro
tied to each of 35 sheets.


--

Dave Peterson


--

Dave Peterson
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default run all worksheet macros

On Aug 13, 3:54 pm, "Trevor Shuttleworth"
wrote:
One way, but a little tedious:

Sub CallSheetMacros()
' assumes macro is called Macro1 in each sheet
Sheet1.Macro1
Sheet2.Macro1
Sheet3.Macro1
:
:
Sheet3.Macro1
End Sub

Sub test()
' more scalable ... still assumes macro is called Macro1 in each sheet
For Each sht In Sheets
On Error Resume Next
sht.Macro1
On Error GoTo 0
Next
End Sub

Regards

Trevor

"Old Fossil Bama" wrote in oglegroups.com...



I have a workbook with 35 worksheets, each with a different macro.


How can I create a workbook level macro torunthe specific macro tied
to each of the 35 worksheets?


Thanks.


I have checked out some previous postings, but theyallseem to apply
a single macro against multiple sheets, but I need to launch a macro
tied to each of 35 sheets.- Hide quoted text -


- Show quoted text -


Thanks, Trevor.

Tried the code like so:

Sub CallSheetMacros()
Sheet1.main
Sheet2.main
Sheet3.main
.........etc
End Sub

The problem is that as each macro was called, the open worksheet focus
remained on Sheet1, resulting in all the succeeding macros being run
against it instead of the corresponding worksheet.

How can I shift focus to the correct sheet each time before the macro
runs?

Something like this:

set focus to Sheet 1
Sheet1.main
set focus to Sheet 2
Sheet2.main
set focus to Sheet 3
Sheet3.main
etc.....

Thanks again.



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default run all worksheet macros

sheet1.select
sheet1.main
sheet2.select
sheet2.main

Old Fossil Bama wrote:

On Aug 13, 3:54 pm, "Trevor Shuttleworth"
wrote:
One way, but a little tedious:

Sub CallSheetMacros()
' assumes macro is called Macro1 in each sheet
Sheet1.Macro1
Sheet2.Macro1
Sheet3.Macro1
:
:
Sheet3.Macro1
End Sub

Sub test()
' more scalable ... still assumes macro is called Macro1 in each sheet
For Each sht In Sheets
On Error Resume Next
sht.Macro1
On Error GoTo 0
Next
End Sub

Regards

Trevor

"Old Fossil Bama" wrote in oglegroups.com...



I have a workbook with 35 worksheets, each with a different macro.


How can I create a workbook level macro torunthe specific macro tied
to each of the 35 worksheets?


Thanks.


I have checked out some previous postings, but theyallseem to apply
a single macro against multiple sheets, but I need to launch a macro
tied to each of 35 sheets.- Hide quoted text -


- Show quoted text -


Thanks, Trevor.

Tried the code like so:

Sub CallSheetMacros()
Sheet1.main
Sheet2.main
Sheet3.main
........etc
End Sub

The problem is that as each macro was called, the open worksheet focus
remained on Sheet1, resulting in all the succeeding macros being run
against it instead of the corresponding worksheet.

How can I shift focus to the correct sheet each time before the macro
runs?

Something like this:

set focus to Sheet 1
Sheet1.main
set focus to Sheet 2
Sheet2.main
set focus to Sheet 3
Sheet3.main
etc.....

Thanks again.


--

Dave Peterson
  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default run all worksheet macros

Aaah ... if the macro name *is* the same on every sheet, I'd be inclined to
go for:

Sub test()
' more scalable ... still assumes macro is called Macro1 in each sheet
Dim sht As Variant
Application.ScreenUpdating = False
For Each sht In Sheets
On Error Resume Next
With sht
.Select
.macro1
End With
On Error GoTo 0
Next
Application.ScreenUpdating = True
End Sub

Saves the repetition

Regards

Trevor


"Old Fossil Bama" wrote in message
oups.com...
On Aug 13, 3:54 pm, "Trevor Shuttleworth"
wrote:
One way, but a little tedious:

Sub CallSheetMacros()
' assumes macro is called Macro1 in each sheet
Sheet1.Macro1
Sheet2.Macro1
Sheet3.Macro1
:
:
Sheet3.Macro1
End Sub

Sub test()
' more scalable ... still assumes macro is called Macro1 in each sheet
For Each sht In Sheets
On Error Resume Next
sht.Macro1
On Error GoTo 0
Next
End Sub

Regards

Trevor

"Old Fossil Bama" wrote in
oglegroups.com...



I have a workbook with 35 worksheets, each with a different macro.


How can I create a workbook level macro torunthe specific macro tied
to each of the 35 worksheets?


Thanks.


I have checked out some previous postings, but theyallseem to apply
a single macro against multiple sheets, but I need to launch a macro
tied to each of 35 sheets.- Hide quoted text -


- Show quoted text -


Thanks, Trevor.

Tried the code like so:

Sub CallSheetMacros()
Sheet1.main
Sheet2.main
Sheet3.main
........etc
End Sub

The problem is that as each macro was called, the open worksheet focus
remained on Sheet1, resulting in all the succeeding macros being run
against it instead of the corresponding worksheet.

How can I shift focus to the correct sheet each time before the macro
runs?

Something like this:

set focus to Sheet 1
Sheet1.main
set focus to Sheet 2
Sheet2.main
set focus to Sheet 3
Sheet3.main
etc.....

Thanks again.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macros for Consolidating data in worksheet 1 on worksheet 2 Omokehinde Excel Programming 1 March 4th 12 01:45 PM
Macros on Protected worksheet Ronnie Excel Discussion (Misc queries) 2 September 28th 07 08:27 PM
Run macros on protected worksheet Lisa D'K Excel Worksheet Functions 0 February 4th 06 08:06 PM
list worksheet macros/VBA without adding worksheet br549 Excel Discussion (Misc queries) 0 January 6th 06 10:17 PM
Worksheet Selections in Macros Karen Excel Worksheet Functions 0 August 29th 05 09:55 PM


All times are GMT +1. The time now is 05:54 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"