P
Paul Simon
I wrote a simple Worksheet Event for a user so that the font color of
any cell she alters in an existing worksheet will be changed to red:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Cells) Is Nothing Then
Selection.Font.ColorIndex = 3
End If
End Sub
Since she will be reusing this code periodically, I copied it to a
text file which I placed on her desktop. The instructions I gave her
for whenever she wants to use this code are simply to open the text
file, Copy the text, right-click on the worksheet tab, choose View
Code from the menu, do Paste to copy in the code, then exit the VBE.
While these instructions are relatively simple, she has asked me for
an automated method. ("Can't you just give me a button to click?")
Accordingly, I'd like to put a macro in her Personal.xls and assign it
to a custom toolbar button so that all she has to do is click the
button to apply the event to whatever worksheet is active at the time.
This needs to be a Worksheet Event rather than a Workbook Event since
she will only be using this on selected worksheet(s) in multiple-sheet
workbooks. Searching this newsgroup, I have only found references to
macros that will apply Workbook Events. I've tried modifying such code
for Worksheet Events but without success.
One of the complications is that the macro code cannot refer to the
worksheet by name since very often the sheet will be something other
than "Sheet1",
What macro code would I use to copy the event into whatever worksheet
is active at the time?
Many thanks,
Paul
any cell she alters in an existing worksheet will be changed to red:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Cells) Is Nothing Then
Selection.Font.ColorIndex = 3
End If
End Sub
Since she will be reusing this code periodically, I copied it to a
text file which I placed on her desktop. The instructions I gave her
for whenever she wants to use this code are simply to open the text
file, Copy the text, right-click on the worksheet tab, choose View
Code from the menu, do Paste to copy in the code, then exit the VBE.
While these instructions are relatively simple, she has asked me for
an automated method. ("Can't you just give me a button to click?")
Accordingly, I'd like to put a macro in her Personal.xls and assign it
to a custom toolbar button so that all she has to do is click the
button to apply the event to whatever worksheet is active at the time.
This needs to be a Worksheet Event rather than a Workbook Event since
she will only be using this on selected worksheet(s) in multiple-sheet
workbooks. Searching this newsgroup, I have only found references to
macros that will apply Workbook Events. I've tried modifying such code
for Worksheet Events but without success.
One of the complications is that the macro code cannot refer to the
worksheet by name since very often the sheet will be something other
than "Sheet1",
What macro code would I use to copy the event into whatever worksheet
is active at the time?
Many thanks,
Paul