打开工具栏中的visual basic 编辑器,在vbaproject工程中插入类模块(系统默认名称为类1),在此类模块中写入如下代码: Public WithEvents aaa As Worksheet Public Sub aaa_selectionchange(ByVal target As Range) target.Cells.Font.ColorIndex = 3 End Sub
接着在vbaproject工程中插入一个模块,在此模块中写入如下代码: Dim tt As 类1 Sub changecolor() Set tt = New 类1 Set tt.aaa = ActiveSheet End Sub Sub endchangecolor() Set tt = Nothing End Sub