我想在excel中使用VB或Macros在5小时后收到通知警报?
发布于 2017-04-09 01:02:24
您可以使用以下三种方法在MS Excel中快速轻松地创建提醒或通知:
- `=IF(B2<TODAY()+3,"Send Reminder","")`
- Click on Home Tab
- In the Styles command group select conditional formatting tab
- Click on New Rule…
- In the new formatting rule window select ‘Use a formula to determine which cells to format’
- Under the ‘Format values where this formula is true:’ write the formula given below
- `=AND(C2<>"",C2<TODAY()+3)`
- Next click on Format and apply the formatting of the cell and font of your choice
for loop的Excel VBA。宏代码如下: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
发布于 2017-04-09 01:41:26
从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 ' minuteshttps://stackoverflow.com/questions/43297913
复制相似问题