Solved

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

Posted on 2016-10-07
10
43 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
  • 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
 
LVL 68

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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 68

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Get an idea of what you should include in an email disclaimer with these Top 5 email disclaimer tips.
Set OWA language and time zone in Exchange for individuals, all users or per database.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now