2010年12月16日星期四

How to use of timers in the Excel

    Excel 97 used in the Add-Ins "time saving" it? Unfortunately, its source is encrypted, and now introduced to upload a document to achieve it.
     There is a way in Office is application.ontime, specific functions are as follows:
     expression.OnTime (EarliestTime, Procedure, LatestTime, Schedule)
     If you would like further information, please see the Excel help.
     This function is used to arrange for a process run at specific times in the future, (the date for a specified period of time, but also after the specified time period). Through this function in Excel where we can write your own regular program. Here are two examples to illustrate it.
     1. In the afternoon, when a dialog box 17:00:00.
     Sub Run_it ()
     Application.OnTime TimeValue ("17:00:00"), "Show_my_msg"
     'Set the timer activated in 17:00:00, activated running Show_my_msg.
     End Sub
    
     Sub Show_my_msg ()
     msg = MsgBox ("Now is 17:00:00!", vbInformation, "Custom Information")
     End Sub
    
    
     2. Imitate Excel 97 in the "auto save the macro", where once in 5 seconds time
     Sub auto_open ()
     MsgBox "Welcome, in this document, once every 5 seconds to save the tips!", VbInformation, "Please pay attention!"
     Call runtimer 'run automatically when you open a document
     End Sub
    
     Sub runtimer ()
     Application.OnTime Now TimeValue ("00:00:05"), "saveit"
     'Now TimeValue ("00:15:00") specified in the current time more than 5 seconds to start running Saveit the process.
     End Sub
    
     Sub SaveIt ()
     msg = MsgBox ("Friends, you've worked a long time, save you now?" & Chr (13) _
     & "Choice: immediately save" & Chr (13) _
     & "Select No: not to save" & Chr (13) _
     & "Choose to cancel: no longer appears this prompt", vbYesNoCancel 64, "take a break now!")
     'Prompt the user to save the current active document.
     If msg = vbYes Then ActiveWorkbook.Save Else If msg = vbCancel Then Exit Sub
     Call runtimer 'If the user does not choose to cancel once again call Runtimer
     End Sub
    
     These are just two simple examples are interested, you can use Application.Ontime this function more useful time to write more programs.

没有评论:

发表评论