I need to run VBA code on startup, and then on two minute intervals thereafter.
Private Sub Application_Startup()
Call doThis
End Sub
Private Sub checkEmail(Item As Outlook.MailItem)
'lots of code here
End Sub
Sub doThis()
Dim myInbox As Outlook.Folder
Dim ToPrint As Outlook.Folder
Dim myNameSpace As NameSpace
Dim objItems As Outlook.Items
Dim objItem As Outlook.MailItem
Set myNameSpace = Application.GetNamespace("MAPI")
Set ToPrint = myNameSpace.GetDefaultFolder(olFolderInbox).Folders("ToPrint")
Set objItems = ToPrint.Items
For Each objItem In objItems
Call checkEmail(objItem)
Next
Application.Ontime Now + TimeValue("00:02:00"), "doThis"
Set myInbox = Nothing
Set ToPrint = Nothing
Set myNameSpace = Nothing
Set objItem = Nothing
Set objItems = Nothing
End Sub
When I get to this line:
Application.Ontime Now + TimeValue("00:02:00"), "doThis"
I get
Run-time error 438:
"Object doesn't support this property or method."