ExcelFans

[清者自清]

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
当在Excel中插入一个批注时,你可以把它调整到不同的位置(如单元格的左边等等)。但是有一个问题,当把批注的显示方式更改为 只显示标示符 后。你移到鼠标到单元格上时批注还是恢复初始的位置-即显示单元格的右方。下面这个小程序就可以解决这个问题。
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
附图:

详见附件:
点击下载
posted on 2008-03-19 17:59  ExcelFans  阅读(6481)  评论(0编辑  收藏  举报