excel - 在 Excel 中使单元格闪烁(宏中的宏)
问题描述
如果 X1 中的值高于 999,我想让一个单元格“Z1”闪烁。我制作了 2 个模块,一个用于在值高于 999 时发出警报,Z1 有一个计数器来检查值高于 999 的次数。现在,每当计数器增加或 X1 值 > 999 时,我需要 Z1 闪烁并恢复到其原始状态。只卡在不闪烁的部分。
下面是我的代码,我哪里错了。
Private BlnAboveHundred1K As Boolean
Private IntCounter1K As Integer
Function TargetCounterROW1COL1(RngMeasure As Range)
If RngMeasure.Value > 999 Then
If BlnAboveHundred1K = False Then
IntCounter1K = IntCounter1K + 1
If Sheets("WorkArea").CommandButton14.Caption = "On" Then
Call PlaySound("c:\windows\media\Alert4.wav", _
0, SND_ASYNC Or SND_FILENAME)
Call StartBlink
End If
BlnAboveHundred1K = True
Else
BlnAboveHundred1K = True
'IntCounter = 0
End If
Else
BlnAboveHundred1K = False
End If
TargetCounterROW1COL1 = IntCounter1K
End Function
下面的单元格闪烁模块
Private IntBlinkCounter As Integer
Sub StartBlink()
Dim xCell As Range
Dim xTime As Variant
On Error Resume Next
Set xCell = Range("WorkArea!Z11")
On Error Resume Next
If xCell.Font.Color = vbRed Then
xCell.Font.Color = vbWhite
Else
xCell.Font.Color = vbRed
End If
xTime = Now + TimeSerial(0, 0, 1)
IntBlinkCounter = IntBlinkCounter + 1
If IntBlinkCounter < 5 Then
Application.OnTime xTime, "'" & ThisWorkbook.Name & "'!StartBlink", , True
End If
End Sub
解决方案
我注释掉了一些行,现在闪烁的宏对我有用:
Sub StartBlink()
Dim xCell As Range
'Dim i As Integer
Dim xTime As Variant
'On Error Resume Next
Set xCell = Range("WorkArea!Z1")
'On Error Resume Next
If xCell.Font.Color = vbRed Then
xCell.Font.Color = vbWhite
Else
xCell.Font.Color = vbRed
End If
xTime = Now + TimeSerial(0, 0, 1)
'i = i + 1
Application.OnTime xTime, "'" & ThisWorkbook.Name & "'!StartBlink", , True
'If i = 6 Then i = 0
'Application.OnTime xTime, "'" & ThisWorkbook.Name & "'!StartBlink", , False
End Sub
此行将宏添加到计划中:
Application.OnTime xTime, "'" & ThisWorkbook.Name & "'!StartBlink", , True
而另一行 从计划中删除宏:
Application.OnTime xTime, "'" & ThisWorkbook.Name & "'!StartBlink", , False
基本上,您添加它并立即将其删除。这就是它从未真正开始的原因。
如果它没有帮助,请尝试更改Call StartBlink
为类似
Application.OnTime Now + TimeSerial(0, 0, 1), "'" & ThisWorkbook.Name & "'!StartBlink", , True
为了在几次眨眼后停止眨眼,你需要两个 thigs。
首先,在闪烁宏之外,在模块的最顶部,创建一个闪烁计数变量,例如:
Private IntBlinkCounter As Integer
二,在StartBlink
宏里面,
Application.OnTime xTime, "'" & ThisWorkbook.Name & "'!StartBlink", , True
用
IntBlinkCounter = IntBlinkCounter + 1
If IntBlinkCounter < 5 Then
Application.OnTime xTime, "'" & ThisWorkbook.Name & "'!StartBlink", , True
End If
推荐阅读
- spring-data - SpringData findAll(Pageable)上的Mockito不匹配方法签名
- javascript - 尝试渲染表格行元素数组时的不变违规
- javascript - 如何在 Laravel 视图中使用 Javascript 进行字符串连接?
- openstack - 为什么openstack neutron linuxbridge cpu 高?
- c# - 如何从 foreach 循环中排除特定类型的控件?
- ruby - 删除记录后删除悬挂的雪貂索引条目
- php - ajax完成后获取图像内容而不是url
- php - php artisan serve 不显示任何输出
- python-sphinx - 使用 `:ref:` 引用一组文件
- c++ - SQLHANDLE-Parameters:函数不接受 x 参数(但实际上是这样)