Run code every few minutes?

Slade2000

Board Regular
Joined
Feb 3, 2009
Messages
118
Hi

How can i run code every few minutes if it is not with in a macro?

I know using this works but does not want to work if it is not a macro you want to run.
Code:
Application.OnTime Now + TimeValue("00:00:30"), "Email"
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
I don't understand your question.

If you want to use the timer event you have to have it as code.

You can place that code behind the workbook event on Activate
 
Upvote 0
This is my code that i want to run every 30 seconds. The code is not in a module it is with in a sheet.

Code:
Sub Email()
    Dim A As Integer
    Dim B As Integer
    Dim C As Integer
    Dim D As Integer
    Dim E As Integer
    Dim F As Integer
    Dim G As Integer
    Dim H As Integer
    Dim I As Integer
   
    If Range("C4").Value < Range("A2").Value Then
      If Range("K4") = "" Then
        Dim OutApp As Object
        Dim OutMail As Object
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
        On Error Resume Next
        With OutMail
        .To = "martin.nel2@standardbank.co.za"
        .CC = ""
        .Subject = "Task not yet completed"
        .Body = "Please check 06:00 tasks not done yet!"
        .Send
        End With
        On Error GoTo 0
        Set OutMail = Nothing
        Set OutApp = Nothing
      If Range("C4") + 0.042 < Range("A2") Then
           Dim OutApp1 As Object
           Dim OutMail1 As Object
           Set OutApp = CreateObject("Outlook.Application")
           Set OutMail = OutApp.CreateItem(0)
           On Error Resume Next
           With OutMail
           .To = "martin.nel2@standardbank.co.za"
           .CC = ""
           .Subject = "Task not yet completed"
           .Body = "Please check 06:00 tasks not done yet!"
           .Send
           End With
           On Error GoTo 0
           Set OutMail = Nothing
           Set OutApp = Nothing
      End If
      End If
    End If
    
    If Range("C5").Value < Range("A2").Value Then
      A = Application.WorksheetFunction.CountIf(Range("K5:K11"), "")
      If A > 0 Then
        MsgBox "Werk"
      End If
    End If
    
    If Range("C12").Value < Range("A2").Value Then
      B = Application.WorksheetFunction.CountIf(Range("K12:K17"), "")
      If A > 0 Then
        MsgBox "Werk"
      End If
    End If
    
    If Range("C18").Value < Range("A2").Value Then
      C = Application.WorksheetFunction.CountIf(Range("K18:K23"), "")
      If A > 0 Then
        MsgBox "Werk"
      End If
    End If
    
    If Range("C24").Value < Range("A2").Value Then
      D = Application.WorksheetFunction.CountIf(Range("K24:K27"), "")
      If A > 0 Then
        MsgBox "Werk"
      End If
    End If
    
    If Range("C28").Value < Range("A2").Value Then
      E = Application.WorksheetFunction.CountIf(Range("K28:K32"), "")
      If A > 0 Then
        MsgBox "Werk"
      End If
    End If
    
    If Range("C33").Value < Range("A2").Value Then
      F = Application.WorksheetFunction.CountIf(Range("K33:K34"), "")
      If A > 0 Then
        Dim OutApp As Object
        Dim OutMail As Object
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
        On Error Resume Next
        With OutMail
        .To = "martin.nel2@standardbank.co.za"
        .CC = ""
        .Subject = "Task not yet completed"
        .Body = "Please check 06:00 tasks not done yet!"
        .Send
        End With
        On Error GoTo 0
        Set OutMail = Nothing
        Set OutApp = Nothing
      If Range("C33") + 0.042 < Range("A2") Then
           Dim OutApp1 As Object
           Dim OutMail1 As Object
           Set OutApp = CreateObject("Outlook.Application")
           Set OutMail = OutApp.CreateItem(0)
           On Error Resume Next
           With OutMail
           .To = "martin.nel2@standardbank.co.za"
           .CC = ""
           .Subject = "Task not yet completed"
           .Body = "Please be adviced that tasks for 11:00 are not done"""
           .Send
           End With
           On Error GoTo 0
           Set OutMail = Nothing
           Set OutApp = Nothing
      End If
      End If
    End If
    
    If Range("C35").Value < Range("A2").Value Then
      If Range("K35").Value = "" Then
        MsgBox "Werk"
      End If
    End If
    
    If Range("C36").Value < Range("A2").Value Then
      G = Application.WorksheetFunction.CountIf(Range("K36:K56"), "")
      If A > 0 Then
        MsgBox "Werk"
      End If
    End If
    
    If Range("C57").Value < Range("A2").Value Then
      H = Application.WorksheetFunction.CountIf(Range("K57:K81"), "")
      If A > 0 Then
        MsgBox "Werk"
      End If
    End If
    
    If Range("C82").Value < Range("A2").Value Then
      I = Application.WorksheetFunction.CountIf(Range("K82:K103"), "")
      If A > 0 Then
        MsgBox "Werk"
      End If
    End If
   [B] Application.OnTime Now + TimeValue("00:00:30"), "Email"[/B]
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,391
Messages
6,119,249
Members
448,879
Latest member
oksanana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top