我有一个Excel 2010工作表和以下要求:
这是我的代码:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static xLastRng As Range
On Error Resume Next
Target.Interior.ColorIndex = 6
xLastRng.Interior.ColorIndex = xlColorIndexNone
Set xLastRng = Target
End Sub
答案 0 :(得分:1)
这是一个有趣的任务!这将需要一些步骤:
1)添加一个标准模块(例如Module1)并创建两个公共变量:
text = "This is a link"
target = "http://example.com"
print(f"\u001b]8;;{target}\u001b\\{text}\u001b]8;;\u001b\\")
2)返回您的工作表事件,您需要使用以下代码:
Public g_lngEXISTINGCOL As Long
Public g_rngPREVIOUSTARGET As Excel.Range
3)为了在保存工作簿之前恢复到原始的内部颜色,您需要双击“ ThisWorkbook”并添加BeforeSave Event:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rngTarget As Excel.Range
On Error Resume Next
Set rngTarget = Application.Intersect(Me.UsedRange, Target)
On Error GoTo 0
If Not rngTarget Is Nothing Then
If rngTarget.Cells.Count = 1 Then
With Target
If Not g_rngPREVIOUSTARGET Is Nothing Then
If g_lngEXISTINGCOL = 16777215 Then
g_rngPREVIOUSTARGET.Interior.ColorIndex = 0
Else
g_rngPREVIOUSTARGET.Interior.Color = g_lngEXISTINGCOL
End If
End If
g_lngEXISTINGCOL = .Interior.Color
Set g_rngPREVIOUSTARGET = Target
.Interior.ColorIndex = 6
End With
End If
End If
End Sub
希望有帮助!