+ Reply to Thread
Results 1 to 2 of 2

VBA Timers

Hybrid View

  1. #1
    Registered User
    Join Date
    10-19-2015
    Location
    Belleville
    MS-Off Ver
    2010
    Posts
    4

    VBA Timers

    Hey guys, i need some help automating a report. It needs to run 24/7 and perform macros every hour. I need the first line in the Starttimer sub to work properly. So if the current date and time is 10/23/2015 08:13:00, the code would generate the following

    RunWhen= (2015,10,23)+(8,0,0)+(1,0,0) = 10/23/2015 09:00:00


    Public RunWhen As Double
    Public Const cRunInterivalHours = 1
    Public Const cRunWhat = "ReportRefresh"
    Public Const cRunSend = "EmailFilePDF"
    Public Const cRunSave = "SaveFilePDF"
    
    Sub Starttimer()
        RunWhen = DateSerial(Now, Now, Now) + TimeSerial(Now, 0, 0) + TimeSerial(cRunInterivalHours, 0, 0)
        Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, Schedule:=True
    End Sub
    
    Sub ReportRefresh()
    
        Worksheets("Report 2").Range("C5").Value = Now()
        ActiveWorkbook.Save
        
            If RunWhen = TimeSerial(8, 0, 0) Then
                Application.OnTime EarliestTime:=RunSe, Procedure:=cRunSave, Schedule:=True
            End If
            
        
             If RunWhen = TimeSerial(6, 0, 0) Then
                 Application.OnTime EarliestTime:=RunSe, Procedure:=cRunSend, Schedule:=True
             End If
        
        Starttimer
    End Sub
    
    Sub SaveFilePDF()
        'change c;\users for local comp
        ChDir "H:\PIC_SHAR\Production Report"
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        "H:\PIC_SHAR\Production Report\Daily Plant Technical Report " & Format(Date - 1, "mmmm dd yyyy") & ".PDF"
        'Change directory to specific folder once detials confirmed
     Starttimer
    End Sub
    
    Sub EmailFilePDF()
        Dim OutLookApp As Object
        Dim OutLookMailItem As Object
        Dim myAttachments As Object
    
        Set OutLookApp = CreateObject("Outlook.application")
        Set OutLookMailItem = OutLookApp.CreateItem(0)
        Set myAttachments = OutLookMailItem.Attachments
    
        With OutLookMailItem
        .To = ""
        '.To = ""
        '.CC = ""
        .Subject = "Daily Technical Report " & Format(Date - 1, "mmmm dd yyyy")
        .Body = "Automated PDF Daily Technical Report, Inventory Calculations need verification"
        myAttachments.Add "H:\PIC_SHAR\Production Report\Daily Plant Technical Report " & Format(Date - 1, "mmmm dd yyyy") & ".PDF"
        .send
        End With
    
        Set OutLookMailItem = Nothing
        Set OutLookApp = Nothing
        Starttimer
    End Sub

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: VBA Timers

    Try something like this...

    RunWhen = Date + TimeSerial(Hour(Time) + cRunInterivalHours, 0, 0)
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need nine timers
    By BM28 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-07-2017, 10:15 PM
  2. Series of timers
    By Subject_Name_Here in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-16-2013, 05:33 PM
  3. Need Help Using Windows Timers
    By PosseJohn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-23-2013, 06:23 PM
  4. Timers
    By excelbobabc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-21-2010, 02:22 PM
  5. Using Timers?
    By captainhillman in forum Excel General
    Replies: 2
    Last Post: 10-27-2010, 06:36 PM
  6. Countdown Timers?
    By phil2006 in forum Excel General
    Replies: 2
    Last Post: 09-11-2007, 07:00 AM
  7. Old Timers
    By Mark@Work in forum Excel General
    Replies: 2
    Last Post: 12-01-2006, 05:05 PM
  8. 2 Timers
    By Al in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-13-2005, 04:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1