Sign in to follow this  
Followers 0
willsonfang

Run Outlook Macro

7 posts in this topic

#1 ·  Posted (edited)

Hi,

First time posting on this forum, just found AutoIt about couple days ago.

I've manage to automate about 10% of my current work, and looking to go further with AutoIt, but have hit a brick wall.

Basically what I'm trying to do is, get AutoIt to run a Outlook macro I have designed.

The general gist of the macro is it saves all attachments from a specific outlook folder, with a date frame and a extension limit to a specified explorer folder.

If there is a more convenient method to do this in AutoIt, I'm up for suggestions (but since the Macro has already been created in Outlook, it should just be easier to call the macro)

I have already seen examples of Excel macros being called, and have tried it myself, but unsure how to replicate it for Outlook.

Regards,

Phoenix

Edited by willsonfang

Share this post


Link to post
Share on other sites



I think MS doesnt support this in versions later than O2000 for seciruty reasons. You can however convert the macro code to Autoit.

Share this post


Link to post
Share on other sites

If you want to convert it to AutoIt please have a look at my OutlookEX UDF.

With function _OL_ItemFind you can limit the number of items to process. With _OL_ItemSave you can save the attachments.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

If you want to convert it to AutoIt please have a look at my OutlookEX UDF.

With function _OL_ItemFind you can limit the number of items to process. With _OL_ItemSave you can save the attachments.

So is a conditional ItemSave possible:

  • Find all Unread emails in a specified folder (hard-coded folder)
  • Filter all emails based on todays date
  • Filter all emails based on if they have a attachment or not
  • Filter all emails based on a whitelist of extentions (4 extensions currently)
  • Dump attachments to a specified folder with todays date as name
That is what my current macro does (found the base of it online, just did small modifications to add extra functionality)

I think MS doesnt support this in versions later than O2000 for seciruty reasons. You can however convert the macro code to Autoit.

Then I would assume, if I use sendkeys and mouse click macros, that is the only way to run the macro?

Edited by willsonfang

Share this post


Link to post
Share on other sites

So is a conditional ItemSave possible:

  • Find all Unread emails in a specified folder (hard-coded folder)
  • Filter all emails based on todays date
  • Filter all emails based on if they have a attachment or not
  • Filter all emails based on a whitelist of extentions (4 extensions currently)
  • Dump attachments to a specified folder with todays date as name
That is what my current macro does (found the base of it online, just did small modifications to add extra functionality)

Yes. I will post an example as soon as I return to my office.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

You can opt. to use send keys but i would advise you not to.

Just post here the macro code - i think it will be easy to convert it to AIT.

There is part of the task already done somewhere in the forums.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

So is a conditional ItemSave possible:

  • Find all Unread emails in a specified folder (hard-coded folder)
  • Filter all emails based on todays date
  • Filter all emails based on if they have a attachment or not
  • Filter all emails based on a whitelist of extentions (4 extensions currently)
  • Dump attachments to a specified folder with todays date as name
An AutoIt script to do what you need could look like (testing needed!):
$oOL = _OL_Open()
 
 
$aFolder = _OL_FolderAccess($oOL, "", $olFolderInbox) ; Access the users inbox
$aItems = _OL_ItemFind($oOL, $aFolder[1], $olMail, "[UnRead]=True And [ReceivedTime]>='12/09/2011 00:00' And [ReceivedTime]<='12/09/2011 23:59'", "", "", "Subject,Body,Attachments,EntryID") ; Find all unread items received today
For $i = 1 to $aItems[0][0] ; Check all found items
    If IsObj($aItems[$i][2]) and $aItems[$i][2].Count > 0 Then ; Does the item have an attachment object and is the number of attachments > 0?
        $aAttachments = _OL_ItemAtttachementGet($ol, $aItems[$i][3])
        For $j = 1 to $aAttachments[0][0] ; This part needs some brush up!!
           If $aAttachments[$j][2] = "xxxx.yyy" Then _OL_ItemSave($oOL, $aItems[$i][3], Default, "C:\temp\", $olTXT, 2)
        Next
    EndIf
Next
_OL_Close($oOL)

Do your mails have either only one attachement or do you always want to save all attachments of a mail?

At the moment I can save an item plus ALL attachments only.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0