Tuesday, 17 January 2012

Run specified macro in specified time of interval throughEXCEL VBA

Open VBA Editor in Excel (Press Alt + F11)

in Project Explorer double click on "ThisWorkbook" and add the following code in it.

Public Sub Workbook_Open()
        Application.OnTime TimeValue(Now + TimeValue("00:15:00")), "DisplayAlarm"
        'specify your desired time. using Time Formula < TimeValue (Hours, Minute, Seconds)>
 End Sub

Now add a Module in the same Workbook and add following Codes

Sub DisplayAlarm()
        MsgBox ("Alarm Triggered")
        'add the additional codes as per your requirement
        'you can use shell command to run any external program
        Call ThisWorkbook.Workbook_Open
End Sub

now save, close and reopen the same excel file.
at the specified time displayAlarm Procedure will run.

Tip: if you add above code in Personal Macro Book then this macro will be available at all the time excel is running because personal macrobook automatically opens with excel

No comments:

Post a Comment

Flattr it