|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 win2009 于 2012-8-24 22:59 编辑
论坛高手的帖子,改造一下,解决显示高亮时,屏幕跟随的问题
值增加了2句代码
ActiveSheet.ScrollArea = Selection.Address
ActiveSheet.ScrollArea = ""- 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 开始()
- ActiveSheet.ScrollArea = Selection.Address
- StartTimer
- End Sub
- Public Sub 结束()
- ActiveSheet.ScrollArea = ""
- StopTimer
- End Sub
复制代码
工作簿1.zip
(19.29 KB, 下载次数: 159)
|
|