Excel VBA 实现电子钟

  
  
  
  
  1. Dim Runtime As Date 
  2.  
  3. Sub RunTimer() 
  4.     Runtime = Now() + TimeValue("00:00:01"
  5.     Application.OnTime Runtime, "my_Procedure" 
  6. End Sub 
  7.  
  8. Sub my_Procedure() 
  9.     Range("A1") = Format(Time, "h:mm:ss"
  10.     RunTimer 
  11. End Sub 

OnTime函数指在某一具体时间执行某一过程,即过程my_Procedure。

执行my_Procedure的时候,就显示现在的时间,然后立即执行Runtime过程,接着就循环下去,效果如下图所示:(颜色大小可以另外设置)

 

 

你可能感兴趣的:(Excel,职场,VBA,休闲)