Skip to content

sebthom.de

Menu
  • Home
  • Über mich
  • Impressum
    • Datenschutzerklärung
  • Gästebuch
Menu

Excel – VBA Timer Example v1.0.1

Posted on Samstag, der 6. April 2002Samstag, der 12. Januar 2013 by sebthom

[lang_en]A friend of mine asked me about how to let excel periodically update some worksheets.
So the first thing I did was searching the web for a solution in Visual Basic for Applications. But the only one I found was to use a 3rd party ActiveX timer control which you have to place onto a userform. Then I found the VBA command “Application.onTime” and had an idea.

Here is my solution only utilizing the VBA onTime command. No need for ActiveX control or any other 3rd party module.[/lang_en]
[lang_de]Ein Freund hatte mich einmal gefragt, ob es nicht irgendwie möglich sei, einzelne Arbeitsblätter in Excel automatisch periodisch aktualisieren zu lassen.
Das erste was ich dann tat, war im Internet nach einer entspr. Lösung in Visual Basic for Applications zu suchen, aber das einzige was ich fand, war ein ActiveX Timer Control eines Drittanbieters, welches man auf einer Userform platzieren muß. Dann fand ich zufällig den VBA Befehl “Application.onTime” und hatte eine Idee.

Hier ist nun meine Lösung, welche nur das VBA onTime Kommando verwendet. Kein ActiveX Control oder irgend ein anderes 3rd-Party Modul sind hierfür notwendig.[/lang_de]

ExcelVBATimer-ScreenShot

  ExcelTimerExample_1.0.1.zip (10,9 KiB, 21.811 hits)

18 thoughts on “Excel – VBA Timer Example v1.0.1”

  1. Luis Diego Villarreal sagt:
    Mittwoch, der 13. Mai 2020 um 21:19 Uhr

    A query. If I have two templates that are using a timer like the example described here, each one independently acquiring electrical data from a PI Data (Excel) database, how can I avoid the two conflicting? in versions prior to office 2016 nothing else separated each excel in separate windows, but now, in 2016 it is not separating the timers and the VB runs them at the same time and the templates remain stuck.

  2. David sagt:
    Donnerstag, der 17. April 2014 um 11:21 Uhr

    Excelent code.
    Thank you so much .

  3. greg sagt:
    Montag, der 11. März 2013 um 17:54 Uhr

    Thanks for the example. I hooked the timer up to 2 buttons, so i could control when it was functioning.

    very useful indeed.

    greg

  4. Adi sagt:
    Mittwoch, der 25. Januar 2012 um 08:12 Uhr

    Super,

    einfach und wirksam.
    Kleiner Fehler in VB interval verweist auf D8,
    da ist aber nichts

  5. SH sagt:
    Sonntag, der 18. Dezember 2011 um 17:31 Uhr

    If close the workbook, how to stop the marco first?

  6. muro sagt:
    Donnerstag, der 28. Juli 2011 um 23:14 Uhr

    thx!

  7. Chandra sagt:
    Mittwoch, der 6. April 2011 um 21:33 Uhr

    How we can activate Timer in Excel so while we lock the system the timer got activated.
    9212034544

  8. Sean sagt:
    Donnerstag, der 31. März 2011 um 15:04 Uhr

    Very helpful to me. Thanks!!

  9. Graham sagt:
    Dienstag, der 20. Juli 2010 um 00:19 Uhr

    Great code – many thanks

  10. Chris (Atlanta GA) sagt:
    Montag, der 1. März 2010 um 01:30 Uhr

    Very cool procedures. You need to edit this line of code to make it work:
    CHANG Cell Reference in “interval = CDbl(Range(“D8″).Value)” to
    interval = CDbl(Range(“D7”).Value)

    Very elegant and nice. Solved my problem

  11. Tony H sagt:
    Mittwoch, der 10. Februar 2010 um 04:45 Uhr

    Thanks for posting this code. I was looking for an example of a on_timer function for Excel that matches the functionality of MFC. This example was more helpful then the Microsoft help.

    Appreciate it.
    T.H.

  12. Alex_F sagt:
    Donnerstag, der 10. Dezember 2009 um 11:25 Uhr

    Super, vielen Dank. Kann ich sehr gut gebrauchen zum periodischen/stündlichen Auslesen eines Temperatursensors am Comport mit Excel.

  13. devit sagt:
    Donnerstag, der 8. Januar 2009 um 11:43 Uhr

    that’s is goodcode!
    excelent!
    oh! yea!
    thank!

  14. Hartmut Gierke sagt:
    Donnerstag, der 6. November 2008 um 20:00 Uhr

    Hi Andrew,

    try the following as VBA code on a worksheet (e.g. table1):
    ”————————————–
    ”Require that all variables be declared
    Option Explicit
    Dim Execute_TimerDrivenMacro As Boolean
    ‘

    Sub Start_OnTimerMacro()
    Execute_TimerDrivenMacro = True
    Application.OnTime Time + TimeValue(“00:00:01”), ActiveSheet.Name & “.OnTimerMacro”
    End Sub

    Sub Stop_OnTimerMacro()
    Execute_TimerDrivenMacro = False
    End Sub

    Public Sub OnTimerMacro()
    If Execute_TimerDrivenMacro Then
    ‘ Do something e.g. put the actual time into cell A1 of the active sheet
    ActiveSheet.Cells(1, 1).Value = Time

    ‘ At the end restart timer
    Application.OnTime Time + TimeValue(“00:00:01”), ActiveSheet.Name & “.OnTimerMacro”
    End If
    End Sub

    Private Sub Worksheet_Activate()
    ‘Start the timer driven method when opening the sheet
    Start_OnTimerMacro
    End Sub

    Private Sub Worksheet_Deactivate()
    ‘Stop the timer driven method when opening the sheet
    Stop_OnTimerMacro
    End Sub
    ”————————————–

    Hope that helps.
    Kind regards,
    Hartmut

  15. Andrew sagt:
    Mittwoch, der 22. Oktober 2008 um 07:39 Uhr

    *just <- early signs of retardation

  16. Andrew sagt:
    Mittwoch, der 22. Oktober 2008 um 07:38 Uhr

    am i jest being retarded, or has the download link been removed?

  17. Alain Bigio sagt:
    Dienstag, der 17. Juni 2008 um 22:49 Uhr

    Dear Sebastian,

    I am trying to update my portfolio by picking up the quotations at Yahoo every 20 minutes. I would like to understand the way this macro works. the button start timer activates which macro. the code I have to put where you say “put your code here” does not seem to execute. Can you please help

    Thank you

    Alain

  18. hr sagt:
    Mittwoch, der 27. Februar 2008 um 17:31 Uhr

    Das Programm verwendet die dafür vorgesehene Excel-VBA-Funktion
    Application.OnTimer(AufrufUhrzeit as Date, NameMeinerSub as String)
    wie in der Excel-Hilfe vorgeschlagen:
    Application.OnTimer( now()+TimeSerial(0,0,5) , NameMeinerSub as String) ‘ 5 Sekunden
    Bug/Problem der Funktion: Wenn die Uhr des PC um 1 Stunde vorgestellt wird, dauert der nächste Aufruf 1 Stunde!

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Kategorien

  • Blog (1)
  • IT (21)
    • Entwicklung (16)
      • Java (7)
      • Jython (4)
      • Visual Basic (5)
    • Linux (3)
    • WebSphere Application Server (1)
    • WebSphere Portal (2)
    • Windows (1)
  • My Freeware (2)
  • My Music (3)

Neueste Beiträge

  • Logging WebSphere API calls in wsadmin scripts
  • [Solved] Windows 7 “Safely Remove Hardware” pop-up menu horrendously slow
  • Bash: Capturing stderr in a variable while still printing to the console.
  • Configuring EMF Teneo with Hibernate, Commons DBCP, Spring Hibernate Transaction Manager, and the OpenSessionInViewFilter
  • Using EMF ECore model objects with Wicket components
  • Installing Tomcat 6 on Debian Squeeze
  • Leveraging PyDev’s auto-completion for indirectly created objects
  • OVal 1.40 released
  • Installing WebSphere Portal in a local network
  • Comparing version numbers in Jython / Python

Blogroll

  • E L S U A
  • elektrofever.de
  • OVal
  • Sweettt.com
  • Twins’ Running Blog

Neueste Kommentare

  • koliko2k3 bei Gästebuch
  • hdkid bei MyPad v1.1.6 – ein PHP Editor
  • Luis Diego Villarreal bei Excel – VBA Timer Example v1.0.1
  • jonathan bei Gästebuch
  • Pierre bei Lotus Notes [Send only] und [Send and File] Schaltflächen für Outlook 2003

Archive

  • Juni 2014
  • Mai 2012
  • Januar 2011
  • Oktober 2010
  • September 2010
  • März 2010
  • Februar 2010
  • September 2009
  • Juli 2009
  • März 2009
  • Februar 2009
  • November 2008
  • September 2008
  • Mai 2008
  • September 2007
  • Juli 2007
  • Juli 2004
  • März 2003
  • August 2002
  • April 2002
  • Januar 2002
  • Deutsch (de)Deutsch
  • English (en)English
© 2023 sebthom.de | Powered by Minimalist Blog WordPress Theme