Question:
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
Answer:
One way would be to use:
- 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 thevbscript
and the equivalentvba
automated from an app such as Excel is that in vbscript you can’t declare types explicitly (ie VBA’sDim strTest As String
isDim StrTest
invbscript
- Use Windows task scheduler to schedule daily execution.
- You will probably need Click Yes to suppress the Outlook security messages.
1234567891011121314151617Dim objAppDim olNsDim olInboxDim olMsgDim olAttOn Error Resume NextSet objApp = CreateObject("Outlook.application")Set olNs = objApp.GetNamespace("MAPI")Set olInbox = olNs.getdefaultfolder(6)Set olMsg = olInbox.items(1)If olMsg.attachments.Count > 0 ThenSet olAtt = olMsg.attachments(1)olAtt.SaveAsFile "c:\temp\" & olAtt.FilenameEnd IfobjApp.QuitSet objApp = Nothing