Option Explicit
Declare Function GetCursorPos _
Lib " user32 " ( _
lpPoint As POINTAPI) _
As Long
Type POINTAPI
X As Long
Y As Long
End Type
Dim ChangeOn As Boolean
Dim OldRange As Range
Dim blnStop As Boolean
Sub StopChange()
On Error Resume Next
If Not blnStop Then
blnStop = True
End If
End Sub
Sub ChangeColor()
Dim LngCurPos As POINTAPI
Dim NewRange As Range, i As Long
If Application.DisplayCommentIndicator <> xlCommentIndicatorOnly Then Exit Sub
On Error Resume Next
blnStop = False
If ChangeOn Then
Exit Sub
Else
ChangeOn = True
End If
Do
If blnStop = True Then Exit Do
GetCursorPos LngCurPos
On Error Resume Next
Set NewRange = ActiveWindow.RangeFromPoint(LngCurPos.X, LngCurPos.Y)
If Err <> 0 Then
If OldRange Is Nothing Then
Else
OldRange.Comment.Visible = False
End If
Else
If NewRange.Address <> OldRange.Address Then
If OldRange Is Nothing Then
Else
OldRange.Comment.Visible = False
End If
If NewRange.Union(NewRange, ActiveSheet.Cells.SpecialCells(xlCellTypeComments)).Address = ActiveSheet.Cells.SpecialCells(xlCellTypeComments).Address Then
With NewRange.Comment.Shape
.Left = NewRange.Left - .Width
.Visible = True
End With
Set OldRange = NewRange
End If
End If
End If
On Error GoTo 0
For i = 1 To 10000
DoEvents
Next
Loop
ChangeOn = False
End Sub
附图: Declare Function GetCursorPos _
Lib " user32 " ( _
lpPoint As POINTAPI) _
As Long
Type POINTAPI
X As Long
Y As Long
End Type
Dim ChangeOn As Boolean
Dim OldRange As Range
Dim blnStop As Boolean
Sub StopChange()
On Error Resume Next
If Not blnStop Then
blnStop = True
End If
End Sub
Sub ChangeColor()
Dim LngCurPos As POINTAPI
Dim NewRange As Range, i As Long
If Application.DisplayCommentIndicator <> xlCommentIndicatorOnly Then Exit Sub
On Error Resume Next
blnStop = False
If ChangeOn Then
Exit Sub
Else
ChangeOn = True
End If
Do
If blnStop = True Then Exit Do
GetCursorPos LngCurPos
On Error Resume Next
Set NewRange = ActiveWindow.RangeFromPoint(LngCurPos.X, LngCurPos.Y)
If Err <> 0 Then
If OldRange Is Nothing Then
Else
OldRange.Comment.Visible = False
End If
Else
If NewRange.Address <> OldRange.Address Then
If OldRange Is Nothing Then
Else
OldRange.Comment.Visible = False
End If
If NewRange.Union(NewRange, ActiveSheet.Cells.SpecialCells(xlCellTypeComments)).Address = ActiveSheet.Cells.SpecialCells(xlCellTypeComments).Address Then
With NewRange.Comment.Shape
.Left = NewRange.Left - .Width
.Visible = True
End With
Set OldRange = NewRange
End If
End If
End If
On Error GoTo 0
For i = 1 To 10000
DoEvents
Next
Loop
ChangeOn = False
End Sub
详见附件:
点击下载