• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

alert pop up

Fat_joe

New Member
please can you help me in setting up an alert pop up function on expiry of an item in excel (VB coding would be much apppreciated)
 
Hello Fat

As per my experience to set up an alert pop-up in Excel using VBA for the expiry of an item, you can use the `Application.OnTime` method to schedule a macro to run at a specific time. Here's an example:

Code:
Sub SetExpirationAlert()
    ' Set the expiration date and time (adjust as needed)
    Dim expirationDate As Date
    expirationDate = #12/31/2023 12:00:00 PM#
    
    ' Calculate the time difference between now and the expiration date
    Dim timeDiff As Double
    timeDiff = expirationDate - Now
    
    ' Schedule a macro to run at the specified expiration time
    Application.OnTime Now + TimeValue("00:00:00") + timeDiff, "ShowAlert"
End Sub

Code:
Sub ShowAlert()
    ' Display a pop-up alert
    MsgBox "Item has expired!", vbExclamation, "Expiration Alert"
End Sub


Here's how to use this code:

1. Press `Alt` + `F11` to open the VBA editor.
2. Insert a new module: `Insert` > `Module`.
3. Copy and paste the code into the module.
4. Modify the `expirationDate` variable to your desired expiry date and time.

Run the `SetExpirationAlert` macro to set up the alert. When the specified expiration time is reached, it will trigger the `ShowAlert` macro, displaying a pop-up alert.
 
Back
Top