-1

I want to make a script rule which sends to a sub folder, marks as certain category and saves attachment (90% of time PDF) in certain g:drive folder with a file naming convention.

Sub folders:

Direct
PO
Confirmation
Delivery Notes
Invoices
Statements

Categories:

PO
Confirmation
Delivery Note
Invoice
Statement

;don't require a "Direct Category"

I'm able to use normal Outlook rules for move to folder and assign category. There are about 30 individual rules based on supplier name. etc.

Had a look at some VBA scripts. Would I need 30 different scripts to tag onto my 30 current move to folder/assign category scripts to assign the separate file name pathways?

Or can I adapt a script that knows if a email hits "Invoice" it saves to G:\My Drive\Outlook attachments\Invoices

Email hits Delivery Notes it saves toG:\My Drive\Outlook attachments\Delivery Notes

File naming Convention; not thought too much into yet.

Date & Time received email and who supplier is. Joe Bloggs Ltd 17.09.21 11.34am

Also a way of marking if any duplicate files Joe Bloggs Ltd 17.09.21 11.34am (2)

Community
  • 1
  • 1
  • You did not indicate what you found. If you did you would reduce suggestions about already seen answers. The usual answer is you need code for each subfolder. ItemAdd is a possibility. https://stackoverflow.com/questions/18497972/adding-listeners-to-different-folders-in-outlook. This should be helpful https://stackoverflow.com/questions/42257360/loop-to-set-up-watches-on-a-selection-of-outlook-folders. – niton Sep 21 '21 at 10:51

1 Answers1

0

You can create a VBA macro where you could subscribe to the ItemAdd event of each folder and depending on the target folder you may run a different code. The ItemAdd event is fired when one or more items are added to the specified collection. For example:

Public WithEvents myOlItems As Outlook.Items 

Private Sub myOlItems_ItemAdd(ByVal Item As Object) 
 
 Dim myOlMItem As Outlook.MailItem 
 Dim myOlAtts As Outlook.Attachments
 Set myOlMItem = myOlApp.CreateItem(olMailItem) 
 
 myOlMItem.Save 
 
 Set myOlAtts = myOlMItem.Attachments 
 
 ' Add new contact to attachments in mail message 
 
 myOlAtts.Add Item, olByValue 
 myOlMItem.To = "Sales Team" 
 myOlMItem.Subject = "New contact" 
 
 myOlMItem.Send 
 
End Sub

Note, an instance of the item that was added is passed as a parameter to the event handler, so you can extract the required information or attachments.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45