Link to home
Start Free TrialLog in
Avatar of JParra72
JParra72

asked on

Schedule Macro Modules to Run Daily at Specific times (Outlook 2010)

Hello,

I have created 9 modules using VBA in outlook.  They send a different email when executed.  I just need to know if I can scheduled them to run daily at specific times.

Attached is a screenshot for one of those modules.User generated image
Thanks for your help.
Avatar of JParra72
JParra72

ASKER

Outlook will be already open at the time the macros run.
ASKER CERTIFIED SOLUTION
Avatar of Helen Feddema
Helen Feddema
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
How can I modify from VBA to VBScript?  by the way what was that first reply from Calle Peter?
Instead of rewriting your code, it might be easier to write PowerShell or VB Script code to trigger the Outlook VBA modules from a scheduled task.
To modify the code, remove the declarations as specific data types, and replace the olMailItem named constant with 0 (its numeric value).  Save each procedure as a .vbs file, and try to run them.  There may be more changes needed.
Another possible alternative is to use repeating tasks, which would trigger creation of emails when they fire.  I have done this, but it takes a lot of programming.  Here is some Access VBA that creates a single task item:
         'Create task item for sending the mail message later
         Set tsk = pappOutlook.CreateItem(olTaskItem)
         strMessage = "When the task reminder fires, an email message will " _
            & "be created and placed in the Outbox to be sent"
         With tsk
            .Display
            .Subject = strTaskSubject
            .DueDate = dteSend
            .StartDate = dteSend
            .Categories = "Reminder"
            .Body = strMessage
            
            'Store info for mail message in unused Task fields
            .BillingInformation = strToEMail
            .CardData = strMessageSubject
            .Mileage = strBody
            
            'Set task reminder for date when message should be sent
            .ReminderSet = True
            .ReminderTime = dteSend
            '.Display
            .Close (olSave)
         End With

Open in new window


and here is an event procedure for the ThisOutlookSession module, that creates the emails when the reminders fire:

Private Sub Application_Reminder(ByVal Item As Object)
'Created by Helen Feddema 1-30-2003
'Last modified 4-1-2004

On Error GoTo ErrorHandler
   
   Dim msg As Outlook.MailItem
   
   If Item.Categories = "Reminder" Then
      Set msg = Application.CreateItem(olMailItem)
      With msg
         msg.To = Item.BillingInformation
         msg.Subject = Item.CardData
         msg.Body = Item.Mileage
         msg.Send
      End With
   End If
   
ErrorHandlerExit:
   Exit Sub

ErrorHandler:
   MsgBox "Error No: " & Err.Number & "; Description: " & _
      Err.Description
   Resume ErrorHandlerExit

End Sub

Open in new window

BillingInformation, CardData and Mileage are built-in properties that don't display on the standard form.  They are very handy for storing miscellaneous data without the need for creating a custom form.
Forget my comment above. Outlook does not allow to run macros from outside it anymore, obviously for security reasons ...
I hate having to provide a reference to StackOverflow, but this VBA code shows a way to use the OS timer to directly call a specific sub. This needs a similar amount of code as the reminder approach, but is more direct and does not have to "misuse" mileage etc. properties.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial