Solved

Scheduling outlook macro to run weekly

Posted on 2010-09-01
2
1,582 Views
Last Modified: 2012-05-10
Hi All,

I'm look for the most efficient way to send a file on your hardrive as an attachement via email.
The closes I've got so far is an Outlook macro
Sub sl()
    Dim olApp As Outlook.Application
    Dim objMail As Outlook.MailItem
    Set olApp = Outlook.Application
    Set objMail = olApp.CreateItem(olMailItem)
    objMail.BodyFormat = olFormatPlain
    objMail.Subject = "Hi buddy"
    objMail.Body = "Whats up" + Chr(13) + Chr(10) + "Greg"
    objMail.To = "putin@email.com"
    objMail.Attachments.Add ("C:\TEMP\test.csv")
    objMail.Send
End Sub


I don't know how to schedule this macro to run Monday morn for example every monday.

Any help would be greatly appreciated (also if you know of another way to automatical email a file that would be helpful as well)

Thanks,
Paul
0
Comment
Question by:B_rider
2 Comments
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 33581395
Create a task in outlook, that recurs for example every Monday.  Now in the VBA create the following code to run the macro:

Chris

To Create a macro:
------------------

Alt + F11 to open the macro editor

  For Applicationevent handlers:
     In the project tree select as appropriate:
      OUTLOOK      : thisOutlookSession
     In the workpane select as appropriate:
      OUTLOOK      : Application
     In the workpane select the required 'event', (i.e. 'open').
     Either
        Insert the required code from the supplied sub into the selected subroutine.
     Or
        Replace the template inserted by the VBE with the sub as supplied

           
  For User Code:
     Insert | Module to insert a code module into the project
     In the project tree select the module.
     Insert the required macro(s) into the selected module, ('Module1' or similar)

Close the Visual Basic Editor.

Check Security as appropriate:
------------------------------

In the application select Tools | Macro | Security
2003 and Earlier : Select Medium
2007 : Outlook - Warnings for all Macros
     : Others - Enable a trusted location and inhibit macros otherwise so do both!
      : Disable Macros
            Office Button, (top left of the screen)
            Options
            Trust Centre
            Trust Centre Settings
            MAcro Settings
            Disable All MAcros with warnings
      : Enable Trusted Locations
            Office Button, (top left of the screen)
            Options
            Trust Centre
            Trust Centre Settings
            Trusted Locations
            Add a preferred location
            ENSURE YOUR FILE IS IN A TRUSTED LOCATION
            Re-open to ensure it is recognised if the above has been changed
            
Select OK
Option Explicit

Private Sub Application_Reminder(ByVal Item As Object)
    sl
End Sub

Sub sl()
    Dim olApp As Outlook.Application
    Dim objMail As Outlook.MailItem
    Set olApp = Outlook.Application
    Set objMail = olApp.CreateItem(olMailItem)
    objMail.BodyFormat = olFormatPlain
    objMail.Subject = "Hi buddy"
    objMail.Body = "Whats up" + Chr(13) + Chr(10) + "Greg"
    objMail.To = "putin@email.com"
    objMail.Attachments.Add ("C:\TEMP\test.csv")
    objMail.Send
End Sub

Open in new window

0
 

Author Comment

by:B_rider
ID: 33694582
Hi this worked great thanks!
0

Featured Post

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!

Question has a verified solution.

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

Find out what you should include to make the best professional email signature for your organization.
In-place Upgrading Dirsync to Azure AD Connect
In this video we show how to create an Address List in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Organization >> Ad…
In this video we show how to create an email address policy in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Mail Flow…

762 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