• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1598
  • Last Modified:

Scheduling outlook macro to run weekly

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
B_rider
Asked:
B_rider
1 Solution
 
Chris BottomleyCommented:
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
 
B_riderAuthor Commented:
Hi this worked great thanks!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now