Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to schedule a macro automatically in outlook?

i want to know how to schedule automatically a macro for outlook. I 've created one macro which extract the attached file from an email and store it in a folder. This macro is working very well when i execute it by clicking macro "execute".

But i want this macro execute automatically everyday for example at 08:30 before coming to my office.

Thank you

like image 535
Pacific Avatar asked Nov 13 '22 11:11

Pacific


1 Answers

One way would be to use:

  1. A vbs to automate Outlook. I've added sample vbscript for saving an attachment from the first item in the Outlook inbox below. The main differences between the vbscript and the equivalent vba automated from an app such as Excel is that in vbscript you can't declare types explicitly (ie VBA's Dim strTest As String is Dim StrTest in vbscript

  2. Use Windows task scheduler to schedule daily execution.

  3. You will probably need Click Yes to suppress the Outlook security messages.

    Dim objApp
    Dim olNs
    Dim olInbox
    Dim olMsg
    Dim olAtt
    On Error Resume Next
    Set objApp = CreateObject("Outlook.application")
    Set olNs = objApp.GetNamespace("MAPI")
    Set olInbox = olNs.getdefaultfolder(6)
    Set olMsg = olInbox.items(1)
    If olMsg.attachments.Count > 0 Then
        Set olAtt = olMsg.attachments(1)
        olAtt.SaveAsFile "c:\temp\" & olAtt.Filename
    End If
    objApp.Quit
    Set objApp = Nothing
    
like image 144
brettdj Avatar answered Dec 05 '22 07:12

brettdj