In this tutorial, we will create an automation that saves the attachments to all the emails in an Outlook Search Folder to your computer, then moves the files to another folder on your computer and renames them by adding today's date to the file name. To rename the files, we will use a formula in the default Project Notebook available in StudioX.
We will create a project and start by adding a Use Outlook Account activity to indicate the Outlook account to use. Inside this activity, we will add a For Each Email activity and then the common scenario Iterate through mail attachments to indicate that we want to save the attachments for each email and then process each file after it is saved. Iterating through each file in the folder where the attachments are saved, we will then add a Write Cell activity to copy the file name and edit the name in the Project Notebook, and a Move File activity to move the file with the updated name to another folder.
- Create two folders named In and Out at the root of the C: drive on your computer.
- Open Outlook, then right-click Search Folders in the Folder pane and select New Search Folder.
- In the New Search Folder window, select Create a custom Search Folder > Choose.
- In the Custom Search Folder window, enter "Last week's attachments" in the Name box and then select Criteria.
- In the Messages tab of the Search Folder Criteria window, from the drop-down menus next to Time select received and Last Week.
- From the More Choices tab, select Only items with and then one or more attachments from the adjacent drop-down menu.
- Click OK three times to close the windows and save the search folder.
- In the Activities panel, select the Outlook tab, and then double-click Use Outlook Account. A Use Outlook Account activity is added to the Designer panel.
- In the activity, the default email account is already selected in the Account field. If you want to use a different account, select it from the drop-down menu.
In the Reference as field, leave the default value
Outlookas the name by which to refer to the account in the automation.
- In the Activities panel, drag the For Each Email activity and drop it inside the Use Outlook Account activity.
- In the For Each Email activity, click Plus on the right side of the In emails from field, and then select Outlook > [Search Folders] > [Last week's attachments]. Your selection is displayed in the field as
Last week's attachments.
You have indicated that you want to iterate through the emails in the Outlook folder "Last week's attachments".
- Click Add activity inside the For Each Email activity and then, in the search box at the top of the screen, select the common scenario Iterate through mail attachments.
- Browse to and select the In folder and click OK.
Two activities are added to your project:
- Save Email Attachments with
CurrentMailselected for the From Message field, indicating that the attachments from the current mail in the iteration should be saved to the In folder that is indicated by the
C:\Inselected in the Save to folder field.
- For Each File In Folder with
C:\Inselected in the Folder field to indicate that you will iterate through the files in this folder.
If you click Start to execute the automation now, the mail attachments are downloaded and saved to the In Folder.
- Save Email Attachments with
- In the Activities panel, select the Excel tab, then drag the Write Cell activity and drop it inside the For Each File In Folder activity.
- In the Write Cell activity:
- Click Plus on the right side of the What to write field and then select CurrentFile > Full Path to indicate that we want to copy the full path of the current file in the iteration.
- Click Plus on the right side of the Where to write field and then select Project Notebook (Notes) > File [Sheet] > FullFileName [Cell] to indicate that we want to paste the full path of the current file in the iteration to the FullFileName named cell in the File sheet of the Project Notebook.
- Click Project Notebook in the StudioX ribbon. In the Project_Notebook.xslx file, go to the File sheet, update the value in the named cell
ReformattedFileName(B14) to the following:
=FileNameNoExtension & "-" & YYYYMMDD & "." & FileExtensionand save the file. This formula adds the current date at the end of the file name.
- In the Activities panel, select the File tab, then drag the Move File activity and drop it after the Write Cell activity inside For Each File In Folder.
- In the Move File activity:
- Click Plus on the right side of the From field and then select CurrentFile > Full Path to indicate the full path of the current file in the iteration.
- Click Plus on the right side of the To field and then select Text. In the Text Builder, enter
C:\Out\and then click Plus on the right side of the window and select Project Notebook (Notes) > File [Sheet] > ReformattedFileName [Cell]. The path in the Text Builder should look like this:
- Make sure the Overwrite option is selected.
- Click Save in the Text Builder.
- Click Save in the StudioX ribbon to save the automation, then click Run to execute the automation.
The attachments from each email in the Outlook Search Folder are saved to the In folder on the computer, then today's date is added to the name and they are moved to the Out folder.
Updated about a month ago