我希望使用VB或宏在5小时后在Excel中获得通知警报?
答案 0 :(得分:0)
您可以使用3种方法快速轻松地在MS Excel中创建提醒或通知:
使用IF功能显示消息
=IF(B2<TODAY()+3,"Send Reminder","")
使用条件格式
=AND(C2<>"",C2<TODAY()+3)
将Excel VBA与for loop
一起使用。宏代码如下:
Private Sub Workbook_Open()
For Each cell In Range("B2:B100")
If cell.Value < Date + 3 And cell.Value <> “” Then
cell.Interior.ColorIndex = 3
cell.Font.ColorIndex = 2
cell.Font.Bold = True
End If
Next
End Sub
Private Sub Workbook_Open()
下的以下代码行初始化上面宏代码中的格式: Range("B2:B100").Interior.ColorIndex = xlNone
答案 1 :(得分:0)
从VBA调用WinAPI存在风险,但您也可以尝试:
Option Explicit
Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal idEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal idEvent As Long) As Long
Public Sub AlertMe(dblMinutes As Double)
Dim idEvent As Long: idEvent = SetTimer(0&, 0&, CLng(dblMinutes * 60 * 1000), AddressOf AlertSub)
End Sub
Public Sub AlertSub(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
KillTimer 0&, idEvent
MsgBox "Alert!"
End Sub
您可以将此保存到例如Personal.xls并以这种方式调用它:
AlertMe 300 ' minutes