PC Review


Reply
Thread Tools Rate Thread

How do I get this Macro to apply to ALL sheets in workbook?

 
 
=?Utf-8?B?TmV3c2dhbA==?=
Guest
Posts: n/a
 
      2nd Aug 2007
Have tried various methods and can't seem to get this Macro to apply to all
the worksheets (January, Feb, March, etc.) in the workbook. Can only get it
to apply to the first one, so you'll see that the January one is the only one
listed below....

Sub StartBlink()
With ThisWorkbook.Worksheets("January").Range("d2:d4").Font
If .ColorIndex = 3 Then ' Red Text
.ColorIndex = 2 ' Yellow Text
Else
.ColorIndex = 3 ' Red Text
End If
End With
RunWhen = Now + TimeSerial(0, 0, 1)
Application.OnTime RunWhen, "'" & ThisWorkbook.Name & "'!StartBlink", ,
True
End Sub
--
News Gal
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9obiBCdW5keQ==?=
Guest
Posts: n/a
 
      2nd Aug 2007
This should get it *untested*

Sub StartBlink()
for i=1 to sheets.count
With ThisWorkbook.Worksheets(i).Range("d2:d4").Font
If .ColorIndex = 3 Then ' Red Text
.ColorIndex = 2 ' Yellow Text
Else
.ColorIndex = 3 ' Red Text
End If
End With
next
RunWhen = Now + TimeSerial(0, 0, 1)
Application.OnTime RunWhen, "'" & ThisWorkbook.Name & "'!StartBlink", ,
True
End Sub

--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"Newsgal" wrote:

> Have tried various methods and can't seem to get this Macro to apply to all
> the worksheets (January, Feb, March, etc.) in the workbook. Can only get it
> to apply to the first one, so you'll see that the January one is the only one
> listed below....
>
> Sub StartBlink()
> With ThisWorkbook.Worksheets("January").Range("d2:d4").Font
> If .ColorIndex = 3 Then ' Red Text
> .ColorIndex = 2 ' Yellow Text
> Else
> .ColorIndex = 3 ' Red Text
> End If
> End With
> RunWhen = Now + TimeSerial(0, 0, 1)
> Application.OnTime RunWhen, "'" & ThisWorkbook.Name & "'!StartBlink", ,
> True
> End Sub
> --
> News Gal

 
Reply With Quote
 
George Nicholson
Guest
Posts: n/a
 
      2nd Aug 2007
Not sure you really meant "apply to all sheets" or if you meant "apply to
any active sheet". If you meant just the ActiveSheet (which is *usually* the
only one the user can see, so there's little point in having the others
blink) then I'd just change
ThisWorkbook.Worksheets("January")
to
ActiveSheet.

On the other hand, it is possible to have more than one sheet/window visible
at a time. So if you really did mean "apply to all
the worksheets in the workbook" then you could try the following. This code
was tested while in a General Module (VB editor>Insert>Module). I also added
an argument that you'll want to remove if you were planning on running this
via Tools>Macros.

Sub StartBlink(Optional bRunBlink As Boolean = True)
Dim dRunWhen As Date
Dim wks As Worksheet

For Each wks In ThisWorkbook.Worksheets
With wks.Range("d2:d4").Font
If .ColorIndex = 3 Then ' Red Text
.ColorIndex = 2 ' Yellow Text
Else
.ColorIndex = 3 ' Red Text
End If
End With
Next wks
dRunWhen = Now + TimeSerial(0, 0, 1)
Application.OnTime dRunWhen, "StartBlink", , bRunBlink
End Sub

StartBlink to start it, StartBlink(False) to stop it.

Note that putzing with screen stuff and running a piece of code every second
BOTH carry performance penalties, so if you only need the active sheet to
blink then limit yourself to that.

HTH,


"Newsgal" <(E-Mail Removed)> wrote in message
news:A05B29CD-C40B-4610-A9FB-(E-Mail Removed)...
> Have tried various methods and can't seem to get this Macro to apply to
> all
> the worksheets (January, Feb, March, etc.) in the workbook. Can only get
> it
> to apply to the first one, so you'll see that the January one is the only
> one
> listed below....
>
> Sub StartBlink()
> With ThisWorkbook.Worksheets("January").Range("d2:d4").Font
> If .ColorIndex = 3 Then ' Red Text
> .ColorIndex = 2 ' Yellow Text
> Else
> .ColorIndex = 3 ' Red Text
> End If
> End With
> RunWhen = Now + TimeSerial(0, 0, 1)
> Application.OnTime RunWhen, "'" & ThisWorkbook.Name & "'!StartBlink", ,
> True
> End Sub
> --
> News Gal



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Apply Conditional Format to all sheets in same workbook Der Musensohn Microsoft Excel Misc 4 26th Feb 2010 04:24 PM
Apply same filter to all sheets in a workbook manfareed Microsoft Excel Programming 9 31st Jul 2008 03:34 PM
apply Macro to all sheets in workbook - loop transferxxx@gmail.com Microsoft Excel Programming 3 19th Jul 2007 08:13 PM
how to apply the same header or footer to all sheets in workbook =?Utf-8?B?THVlbmRhIEJ1cmtl?= Microsoft Excel Worksheet Functions 1 1st Nov 2006 05:45 PM
apply same custom header to all sheets in a workbook jchoy Microsoft Excel Misc 2 20th Aug 2004 01:15 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:22 PM.