VBA in Outlook 2007

Posted on 2011-09-20
Last Modified: 2012-05-12
hello experts,

We are trying to add a command button to menus in outlook that will allow users to save emails into folders on their computer.  At first we were simply dragging the messages out into folders and users were happy because it was simple and was not time consuming.  We have since found that this causes problems because emails have the same name when in an email thread so old copies are overwritten.  Users, being users, are dead against renaming files once they have been dragged out because it is too time consuming!!  Would it be possible to safely code something in outlook and run it from a macro button that would, say, export an email in a single click only to prompt for a file location?  And is this the best way to accomplish this?  What we are trying to do (big picture wise) is stop having to print emails and create paper files for correspondance.  Because we already file word documents we want the emails to be in the same place but don't want to pay for a paperless system due to funds.....any suggestions?


Question by:computer_says_no
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 47

Expert Comment

ID: 36576499
"We are trying to add a command button to menus in outlook that will allow users to save emails into folders on their computer"

Why are they trying to save emails to Folders on a Computer?

Is there any reason why the Built in Functionality of Outlook Personal Folders is not being used.

Especailly since, when they are used you can use the Move Button in the Outlook Ribbon which is populated with folder options from the PST.

So basically works exactly like you descibe above, however into a PST, not a Folder Structure on the Users Local PC.
LVL 31

Accepted Solution

Helen Feddema earned 500 total points
ID: 36576746
What you want is possible, but in addition to selecting the folder, you might also need to allow message renaming, since otherwise you may have problems with overwriting.  Here is some sample code for saving the currently open message to a user-selected folder (you may have problems with permission for some folders, though):
Public Sub SaveMessage()
'Created by Helen Feddema 21-Sep-2011
'Last modified by Helen Feddema 21-Sep-2011

On Error GoTo ErrorHandler

   Dim ins As Outlook.Inspector
   Dim msg As Outlook.MailItem
   Dim itm As Object
   Dim strPath As String
   Dim fd As Office.FileDialog
   Dim appWord As New Word.Application
   'Create a FileDialog object as a Folder Picker dialog box
   '(have to use Word because the Outlook Application object
   'lacks a FileDialog property)
   Set fd = appWord.FileDialog(msoFileDialogFolderPicker)
   With fd
      .Title = "Browse for folder where message should be saved"
      .ButtonName = "Select"
      .InitialView = msoFileDialogViewDetails
      If .Show = -1 Then
         strPath = CStr(fd.SelectedItems.Item(1))
         Debug.Print "User pressed Cancel"
      End If
   End With
   Set ins = Application.ActiveInspector
   Set itm = ins.CurrentItem
   If itm.Class = olMail Then
      Set msg = ins.CurrentItem
      msg.SaveAs Path:=strPath, Type:=olMSG
      msg.Close (olDiscard)
   End If
   Set fd = Nothing
   Set appWord = Nothing
   Exit Sub

   MsgBox "Error No: " & Err.Number _
      & " in SaveMessage procedure; " _
      & "Description: " & Err.Description
   Resume ErrorHandlerExit

End Sub

Open in new window


Author Comment

ID: 36709215
thanks for the responses....

apache08 - it's simply because the system is to replace a physical folder full of printed emails and documents and we want to keep the process the same, so we figured to drag emails out into the folder where documents are already stored would be the easiest?  I would really like to use something more robust (emails in folders makes me uncomfortable) but this means spending on a paperless office type system which we cannot afford at the moment

helen - looks like it will do exactly as I wanted...

It's a tricky one, not sure of the best way forwards really, either way there will be an intervention to name and place the file, there is no way to fully automate because email subjects could have been stipulated by the email sender and will therefore not conform to the structure we need. Headache!!


LVL 101

Expert Comment

ID: 37068436
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
Changing a few Outlook Options can help keep you organized!
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question