Excel中实现鼠标指向哪个单元格那个单元格就变色
2008-02-20 16:57
369 查看
在工作薄中的任意工作表中添加两个窗体按钮控件,将指定其设置宏 分别指定为为ChangeColor 和 StopChange。其供示范之用
效果图:
模块中代码:
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 OldColorIndex As Integer
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
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
OldRange.Interior.ColorIndex = OldColorIndex
Else
If NewRange.Address <> OldRange.Address Then
If OldRange Is Nothing Then
Else
OldRange.Interior.ColorIndex = OldColorIndex
End If
OldColorIndex = NewRange.Interior.ColorIndex
NewRange.Interior.ColorIndex = 3
End If
Set OldRange = NewRange
End If
On Error GoTo 0
DoEvents
Loop
ChangeOn = False
End Sub
效果图:
模块中代码:
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 OldColorIndex As Integer
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
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
OldRange.Interior.ColorIndex = OldColorIndex
Else
If NewRange.Address <> OldRange.Address Then
If OldRange Is Nothing Then
Else
OldRange.Interior.ColorIndex = OldColorIndex
End If
OldColorIndex = NewRange.Interior.ColorIndex
NewRange.Interior.ColorIndex = 3
End If
Set OldRange = NewRange
End If
On Error GoTo 0
DoEvents
Loop
ChangeOn = False
End Sub
相关文章推荐
- Excel实现单元格下拉菜单并设置变色
- Excel实现单元格下拉菜单并设置变色
- 鼠标移动到某个单元格上后,整个列都变色的实现方法
- 鼠标移动到某个单元格上后,整个列都变色的实现方法
- excel的单元格怎么实现下拉菜单?
- excel中非纯数字格式的列,鼠标向下拖动实现自增的方法
- 一个简单但常用的表格样式--鼠标划过行变色--简洁实现
- (C#)DataGrid实现自定义分页,鼠标移至变色,删除确认、可编辑,可删除
- js实现表格隔行变色和鼠标移入高亮
- 用jquery实现单双行变色以及鼠标经过时也同时变色
- Excel录入中实现单元格多选项自动下拉
- Gridview的数据列中实现鼠标悬浮变色
- CSS+DIV实现鼠标经过背景变色
- 实现 鼠标点击表格行背景变色,移开后点击另一行时另一行变色而前一行恢复原来的背景色
- Repeater中实现“鼠标滑动行变色”的效果
- jQuery实现table隔行换色和鼠标经过变色
- cc150:实现一个算法来删除单链表中间的一个结点,只给出指向那个结点的指针
- js实现表格隔行变色,鼠标在该行放上移走的变色效果,还有全选,反选等
- QML鼠标事件实现变色矩形
- jquery特效 table鼠标滑过变色的实现代码