Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 23
Default Applying a macro to all worksheets

I have a macro that contains the line:

With Worksheets("UK")

Can I get it to apply to all my worksheets?

Ie

With Worksheets(All)

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 23
Default Applying a macro to all worksheets

Use something like With Worksheets(Activesheet)

this will work with any worksheet.

There is no worksheets(All) as all the worksheets is really the
workbook collection

DannyS wrote:
I have a macro that contains the line:

With Worksheets("UK")

Can I get it to apply to all my worksheets?

Ie

With Worksheets(All)

Thanks!


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 23
Default Applying a macro to all worksheets


Great stuff, thanks again to you two guys!

"PMC1" wrote:

Use something like With Worksheets(Activesheet)

this will work with any worksheet.

There is no worksheets(All) as all the worksheets is really the
workbook collection

DannyS wrote:
I have a macro that contains the line:

With Worksheets("UK")

Can I get it to apply to all my worksheets?

Ie

With Worksheets(All)

Thanks!



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 23
Default Applying a macro to all worksheets

Ah, hang on. When I use Activesheets I get a runtime error. My macro looks
like this:

Sub auto_open()
With Worksheets(ActiveSheet)
.Protect Password:="hi", userinterfaceonly:=True
.EnableOutlining = True
'.EnableAutoFilter = True
End With
End Sub

"PMC1" wrote:

Use something like With Worksheets(Activesheet)

this will work with any worksheet.

There is no worksheets(All) as all the worksheets is really the
workbook collection

DannyS wrote:
I have a macro that contains the line:

With Worksheets("UK")

Can I get it to apply to all my worksheets?

Ie

With Worksheets(All)

Thanks!



  #5   Report Post  
Posted to microsoft.public.excel.misc
CLR CLR is offline
external usenet poster
 
Posts: 1,998
Default Applying a macro to all worksheets

maybe.......

With Activesheet

Vaya con Dios,
Chuck, CABGx3





"DannyS" wrote:

Ah, hang on. When I use Activesheets I get a runtime error. My macro looks
like this:

Sub auto_open()
With Worksheets(ActiveSheet)
.Protect Password:="hi", userinterfaceonly:=True
.EnableOutlining = True
'.EnableAutoFilter = True
End With
End Sub

"PMC1" wrote:

Use something like With Worksheets(Activesheet)

this will work with any worksheet.

There is no worksheets(All) as all the worksheets is really the
workbook collection

DannyS wrote:
I have a macro that contains the line:

With Worksheets("UK")

Can I get it to apply to all my worksheets?

Ie

With Worksheets(All)

Thanks!





  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default Applying a macro to all worksheets

In the same way that you can not select multipe sheets and protect them
manually, you can not have VBA protect multiple sheets at once. What you can
do is have VBA cycle through all of the sheets and process them one at a time
something like this...

Sub auto_open()
dim wks as worksheet

for each wks in worksheets
with wks
.Protect Password:="hi", userinterfaceonly:=True
.EnableOutlining = True
'.EnableAutoFilter = True
End With
next wks
End Sub

--
HTH...

Jim Thomlinson


"DannyS" wrote:

Ah, hang on. When I use Activesheets I get a runtime error. My macro looks
like this:

Sub auto_open()
With Worksheets(ActiveSheet)
.Protect Password:="hi", userinterfaceonly:=True
.EnableOutlining = True
'.EnableAutoFilter = True
End With
End Sub

"PMC1" wrote:

Use something like With Worksheets(Activesheet)

this will work with any worksheet.

There is no worksheets(All) as all the worksheets is really the
workbook collection

DannyS wrote:
I have a macro that contains the line:

With Worksheets("UK")

Can I get it to apply to all my worksheets?

Ie

With Worksheets(All)

Thanks!



  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 23
Default Applying a macro to all worksheets


Yes!

Great stuff - thanks Jim!


"Jim Thomlinson" wrote:

In the same way that you can not select multipe sheets and protect them
manually, you can not have VBA protect multiple sheets at once. What you can
do is have VBA cycle through all of the sheets and process them one at a time
something like this...

Sub auto_open()
dim wks as worksheet

for each wks in worksheets
with wks
.Protect Password:="hi", userinterfaceonly:=True
.EnableOutlining = True
'.EnableAutoFilter = True
End With
next wks
End Sub

--
HTH...

Jim Thomlinson


"DannyS" wrote:

Ah, hang on. When I use Activesheets I get a runtime error. My macro looks
like this:

Sub auto_open()
With Worksheets(ActiveSheet)
.Protect Password:="hi", userinterfaceonly:=True
.EnableOutlining = True
'.EnableAutoFilter = True
End With
End Sub

"PMC1" wrote:

Use something like With Worksheets(Activesheet)

this will work with any worksheet.

There is no worksheets(All) as all the worksheets is really the
workbook collection

DannyS wrote:
I have a macro that contains the line:

With Worksheets("UK")

Can I get it to apply to all my worksheets?

Ie

With Worksheets(All)

Thanks!


  #8   Report Post  
Posted to microsoft.public.excel.misc
CLR CLR is offline
external usenet poster
 
Posts: 1,998
Default Applying a macro to all worksheets

maybe.......

With Activesheet

Vaya con Dios,
Chuck, CABGx3



"DannyS" wrote:

I have a macro that contains the line:

With Worksheets("UK")

Can I get it to apply to all my worksheets?

Ie

With Worksheets(All)

Thanks!

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
Same macro - Different Worksheets!? PaulW Excel Discussion (Misc queries) 2 December 12th 06 11:55 AM
Copying data to multiple worksheets by Macro lqfong Excel Discussion (Misc queries) 0 June 26th 06 03:57 AM
automatically apply a macro to all worksheets minrufeng Excel Discussion (Misc queries) 5 February 21st 06 09:34 PM
Applying same macro to all worksheets in workbook [email protected] Excel Discussion (Misc queries) 2 October 19th 05 11:25 PM
CREATE MACRO TO COPY MULTIPLE WORKSHEETS Bewilderd jim Excel Discussion (Misc queries) 5 March 3rd 05 10:00 PM


All times are GMT +1. The time now is 03:13 AM.

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

About Us

"It's about Microsoft Excel"