Tutorial: Macro for MS/Outlook - Forward Multiple Mails

Working with e-mail import from older mail-servers sometimes requires forwarding mail to another mailbox. This tutorial describes a method to forward mails in bulk from MS/Outlook. 

Maverick is able to import mails (including attachments). This can be helpful when the client has a mail-address to which suppliers can send their invoices by mail. Maverick checks the mail address and import the invoices automatically in Maverick.

In some cases the client uses an old mail-server setup which does not support Secure IMAP (Microsoft Exchange for example). From a security point-of-view the client doesn't grant access to Maverick to contact the mail-server. To solve this, a @streamconsulting.nl address is used to import the mails into Maverick. The client can forward the mails (with the attached invoices) to the @streamconsulting address.

To forward the messages there are a few possibilities.

  • The IT department can define a rule to forward all messages to the @streamconsulting address;
  • The employee from the Finance Department can forward the messages to the @streamconsulting address (or he can define a rule for this in, let's say Outlook).

However, one client of us experienced that suppliers are not only sending invoices to the invoice@client.com address but also other type of messages (for example to communicate the new prices). Of course this messages can be deleted in Maverick but in this case the client wants to decide which mails needs to be imported in Maverick. So he can open the invoice@client.com mailbox and forward the mails to the @streamconsulting address. However, in Microsoft Outlook you can't forward multiple messages as seperate messages (Outlook will always sends one mail with the other mails as attachments).

At Stream we have developed a macro for Outlook which forwards the messages as separate messages. The employee can select multiple messages in Outlook. On his toolbar there is a button 'Forward to Maverick'. When he clicks on the button, the mails are forwarded and at the same time moved to a folder 'Archive'.

Below is a tutorial on the setup.

  1. Open Microsoft Outlook.
  2. Press Alt-F11
  3. Paste the following code in the Module

Sub ForwardMultipleMail()
'Forward the selected email to Stream
On Error Resume Next
Dim objMail As Outlook.MailItem
Dim objItem As Outlook.MailItem
Dim objApp As Outlook.Application

Set objApp = Application

If objApp.ActiveExplorer.Selection.Count = 0 Then 'When no message selected, quit.
  Exit Sub
End If

For Each objItem In objApp.ActiveExplorer.Selection
  Set objMail = objItem.Forward
  objMail.To = "xxxx@streamconsulting.nl" 'The email address to forward the mail to
  objMail.Subject = "Forwarded " + objMail.Subject
  objMail.Send
  Call MoveMessageToFolder(objItem, "Archived") 'move the mail to the specified folder
 
  Set objMail = Nothing
  Set objItem = Nothing
Next
End Sub

Private Sub MoveMessageToFolder(objItem As Outlook.MailItem, ByVal sFolder As String)
On Error Resume Next
Dim objFolder As Outlook.MAPIFolder
Dim objInbox As Outlook.MAPIFolder
Dim objNS As Outlook.NameSpace
Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Set objFolder = objInbox.Folders(sFolder)
If objFolder Is Nothing Then
  MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER"
End If

objItem.Move objFolder
'Clean up
Set objFolder = Nothing
Set objInbox = Nothing
Set objNS = Nothing

End Sub
  1. Save the code.
  2. Go to the toolbar. Click on the right mouse-button.
  3. Select 'Customize'.
  4. Select the tab 'Toolbar'.
  5. Click on 'New'.
  6. Type a name for the new toolbar. Click on 'Ok'.
  7. Drag the new toolbar to the toolbar on the top of your screen.
  8. Go to the tab 'Commands'.
  9. Go to 'Macros'.
  10. Drag and drop the newly created macro to the toolbar.
  11. Click on close.

To test the macro, select a couple of mails and click on the button in the toolbar. The mails now should be send to the mail address specified in the macro and the message should be moved to the specified folder.

 

Remarks:

Sometimes the macro doesn't run because of a tight security on macro's. You can sign the macro or you can lower the security settings (in that case you need to restart Microsoft Outlook).