Excel VBA for e-clock

Source: Internet
Author: User

Source: http://mcdelfino.blog.51cto.com/2058744/691026

Dim Runtime As Date 'defines the time variable Sub RunTimer () Runtime = Now () + TimeValue ("00:00:02")'. The time is displayed As an increase of 1 second Application. onTime Runtime, "my_Procedure" 'execute the following process at the specified Time: End Sub my_Procedure () Range ("A1") = Format (Time, "h: mm: ss ") 'display the current system Time (Time) RunTimer in the specified table 'and continue executing the above program End Sub

The OnTime function is used to execute a specific process at a specific time, that is, the process my_Procedure.

When my_Procedure is executed, the current time is displayed, and the Runtime process is executed immediately, and then the loop goes down. The effect is shown in: (you can set the color size separately)

Concepts involved:

  1. Date data type: Indicates the time from January 1, January 1-9, 0001, December 31, 999, and from midnight 12:00:00 to 11:59:59. 9999999. The default value of Date is January 1, 0001 0:00:00 (midnight ).
  2. Now Function: Returns the current date and time in datetime format.
  3. Time Function: Returns the current system time.
  4. TimeValue Function: Converts the time in text format to the time in date and time format.
  5. Application. OnTime Function: Schedule a process to run at a specific time in the future (either after a specific time or after a specified time ).
      OnTime (EarliestTime,Procedure,LatestTime,Schedule)
    The following two parameters are optional!
    The method of Application. OnTime Runtime, "my_Procedure" for a single row cannot be enclosed by brackets. If the assignment operation is involved, brackets are required!
  6. Worksheet. Cells attributes: When no parameter is set, it indicates all cells in the worksheet. If one parameter is set, the cells in the first row are displayed. If two parameters are set, the rows and columns are displayed!
        With Cells(2, 2).Font        .Size = 20        .Color = RGB(255, 0, 0)        .Name = "Arial Black"        .FontStyle = "Bold Italic"    End With
  7. Worksheet. Range attribute: Indicates a cell or cell area.
  8. Format Function: Return according to the formatStringA string containing the instruction setting format in the expression. The format contains predefined symbols, which indicate different display formats!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.