|
本帖最后由 win2009 于 2012-9-20 08:36 编辑
论坛的帖子,值得借鉴
- Option Explicit
- '鼠标经过高亮显示
- Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
- Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
- Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
- Type POINTAPI
- x As Long
- y As Long
- End Type
- Dim m_blnTimerOn As Boolean
- Dim m_lngTimerId As Long
- Dim m_NewRange As Range
- Dim m_OldRange As Range
- Sub StartTimer()
- If Not m_blnTimerOn Then
- m_lngTimerId = SetTimer(0, 0, 0.05, AddressOf TimerProc)
- m_blnTimerOn = True
- ' Set m_OldRange = ActiveSheet.Range("A1")
- End If
- End Sub
- Public Function TimerProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
- Dim lngCurPos As POINTAPI
- '
- On Error Resume Next
- GetCursorPos lngCurPos
- Set m_NewRange = ActiveWindow.RangeFromPoint(lngCurPos.x, lngCurPos.y)
- With m_NewRange
- If m_OldRange.Address <> .Address Then
- Dim r As Long, c As Long
- r = .Row
- c = .Column
- Rows(r).Select
- ' Union(Columns(c), Rows(r)).Select '这句行列同时选定
- End If
- End With
- Set m_OldRange = m_NewRange
- TimerProc = 0
- End Function
- Sub StopTimer()
- If m_blnTimerOn Then
- KillTimer 0, m_lngTimerId
- m_blnTimerOn = False
- End If
- End Sub
- Public Sub 开始()
- StartTimer
- End Sub
- Public Sub 结束()
- StopTimer
- End Sub
复制代码 屏幕固定功能以实现,替换下面两个代码,就行你试试
Public Sub 开始()
ActiveSheet.ScrollArea = ActiveCell.Address
StartTimer
End Sub
Public Sub 结束()
ActiveSheet.ScrollArea = ""
StopTimer
End Sub |
|