Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


VBA in Outlook 2007

Posted on 2011-09-20
Medium Priority
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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

715 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