Solved

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

Posted on 2016-10-07
10
847 Views
Last Modified: 2016-10-09
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.screenshot for one of those modules
Thanks for your help.
0
Comment
Question by:JParra72
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
10 Comments
 

Author Comment

by:JParra72
ID: 41834306
Outlook will be already open at the time the macros run.
0
 
LVL 31

Accepted Solution

by:
Helen Feddema earned 500 total points
ID: 41834328
If you can modify the code from VBA to VBScript, and save each procedure as a .vbs file, you should be able to run them from the Windows Scheduler.  As I recall (it has been a while since I made any VBScript files), you can't declare objects as specific data types, or use most named constants (replace olMailItem with the numeric value, 0), but otherwise I think your code would work.
0
 

Author Comment

by:JParra72
ID: 41834337
How can I modify from VBA to VBScript?  by the way what was that first reply from Calle Peter?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 70

Expert Comment

by:Qlemo
ID: 41835149
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.
0
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 41835151
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.
0
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 41835155
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

0
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 41835158
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.
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 41835740
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.
0
 

Assisted Solution

by:JParra72
JParra72 earned 0 total points
ID: 41835980
Hello,

I appreciate the help and input from everyone.  I have accomplished what  I needed by creating a VBScript and scheduling it to run daily in the Windows scheduler.

Here is the script:

'Send email with phone report

Set objOutlook = CreateObject("Outlook.Application")
   Set objMail = objOutlook.CreateItem(0)

          objMail.to = "email@tosendto.com"
          objMail.Subject  = "3pm Summary Phone Report"
          objMail.Attachments.Add("C:\Phone Report\3pm_phone_report.pdf")
          objMail.Body = "Phone Calls, Inbound and Outbound Calls until 3pm"
          objMail.Send

Open in new window

0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
Mailbox Overload?
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question