Exporting an Outlook Distribution List to Excel


Here’s a question I stumbled across last week on Twitter.

As I explained in my reply to Caity, there is a way to do it. This YouTube video from The SmartVA shows how. In short, you have to open the distribution list, act like you’re going to send it to someone else in internet format, open the attachment in the resulting email, copy the contents, then launch Excel and paste the list into a spreadsheet. That’s too many steps, especially if you need to export distribution lists regularly. We should able to export a distribution list with at most two actions: select the list, export it. If only there were some way to automate the process.

VBA to the rescue. With a few lines of code we can make exporting a distribution list a no-brainer. Select the list and run the macro. Out comes a spreadsheet with the names in column A and the addresses in column B. It’s hard to get much simpler than that. Hopefully this solution will be more to Caity’s liking, yours too, than the process the video describes.
Continue reading

Creating Custom Reminders


I was on Twitter last night looking for tweets about Outlook when I stumbled across this one.

Here’s my reply and Jake’s follow-up.

Creating some reminders is easy enough so I put a solution together for Jake. Here’s how it works.

When Jake runs the macro it will prompt him for the name of a client. Once he enters that the macro will create the three reminders Jake wants. The macro includes options allowing Jake to control the type of reminder (task or calendar event), the reminder’s subject line, the category the reminders will belong to (Jake can color code them if he wants), the number of minutes before the event’s start time to show the reminder (if Jake sets the type to Event), the time to display the reminders (if Jake set the type to Task), and the length of the event on the calendar (if Jake sets the type to Event).

Adding the code to Outlook.

  1. Start Outlook
  2. Press ALT+F11 to open the Visual Basic Editor
  3. If not already expanded, expand Microsoft Office Outlook Objects
  4. If not already expanded, expand Modules
  5. Select an existing module (e.g. Module1) by double-clicking on it or create a new module by right-clicking Modules and selecting Insert > Module.
  6. Copy the code from the code snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
  7. Edit the code as desired. I included a comment wherever something can be changed.
  8. Click the diskette icon on the toolbar to save the changes
  9. Close the VB Editor
Sub CreateReminders()
    '--> Create some constants
    'On the next line set the reminder type to either Event (to put the reminders on your calendar) or Task (to add the reminders to your task list).
    Const REM_TYPE = "Task"
    'On the next line edit the default reminder subject line.  The client's name will be appended to the subject.
    Const REM_SUBJECT = "Call Client - "
    'On the next line edit the name of the category to be assigned to all reminders
    Const REM_CATEGORY = "Client Calls"
    'On the next line edit the number of minutes before the start of the of the appointment to show the reminder.  Only used if REM_TYPE is set to Event.
    Const REM_MINUTES = 5
    'On the next line edit the time reminders will be shown.  Only used if the REM_TYPE is set to Task.
    Const REM_TIME = #9:00:00 AM#
    'On the next line edit the default length of the appointment in minutes.  Only used if the REM_TYPE is set to Event.
    Const REM_DURATION = 15
    Const SCRIPT_NAME = "Create Reminders"
    
    '--> Create some variables
    Dim olkApt As Outlook.AppointmentItem, olkTsk As Outlook.TaskItem, strClient As String, intCnt As Integer, bolCreated As Boolean
    
    '--> Initialize some variables
    bolCreated = True
    
    '--> Main routine
    'Get the client's name.
    strClient = InputBox("Enter the name of the client to contact.", SCRIPT_NAME)
    'Was a name entered?
    If strClient = "" Then
        'No
        MsgBox "Operation cancelled.  You must enter a client's name for this macro to work.", vbCritical + vbOKOnly, SCRIPT_NAME
    Else
        'Yes
        'Create the three reminders: 14 days, 1 month, and 3 months
        For intCnt = 1 To 3
            Select Case REM_TYPE
                'Create events
                Case "Event"
                    Set olkApt = Application.CreateItem(olAppointmentItem)
                    olkApt.Subject = REM_SUBJECT & strClient
                    Select Case intCnt
                        Case 1
                            olkApt.Start = DateAdd("d", 14, Date) & " " & REM_TIME
                        Case 2
                            olkApt.Start = DateAdd("m", 1, Date) & " " & REM_TIME
                        Case 3
                            olkApt.Start = DateAdd("m", 3, Date) & " " & REM_TIME
                    End Select
                    olkApt.Duration = REM_DURATION
                    olkApt.ReminderSet = True
                    olkApt.ReminderMinutesBeforeStart = REM_MINUTES
                    olkApt.Categories = REM_CATEGORY
                    olkApt.Save
                'Create tasks
                Case "Task"
                    Set olkTsk = Application.CreateItem(olTaskItem)
                    olkTsk.Subject = REM_SUBJECT & strClient
                    Select Case intCnt
                        Case 1
                            olkTsk.DueDate = DateAdd("d", 14, Now)
                        Case 2
                            olkTsk.DueDate = DateAdd("m", 1, Now)
                        Case 3
                            olkTsk.DueDate = DateAdd("m", 3, Now)
                    End Select
                    olkTsk.ReminderSet = True
                    olkTsk.ReminderTime = olkTsk.DueDate & " " & REM_TIME
                    olkTsk.Categories = REM_CATEGORY
                    olkTsk.Save
                'REM_TYPE has an invalid value
                Case Else
                    bolCreated = False
                    Exit For
            End Select
        Next
        If bolCreated Then
            MsgBox "I created the reminders.", vbInformation + vbOKOnly, SCRIPT_NAME
        Else
            MsgBox "Operation cancelled.  The reminder type is invalid.  Valid types are 'Event' and 'Task'.", vbCritical + vbOKOnly, SCRIPT_NAME
        End If
    End If
    
    '--> Clean up
    Set olkApt = Nothing
    Set olkTsk = Nothing
End Sub

Adding Buttons to Run the Macro with a Single Click

If Jake wants to run the macro with a single click, then he’ll need to add a toolbar button in Outlook 2007 or a button on the Quick Access Toolbar (QAT) for Outlook 2010.

Outlook 2007. Follow these instructions to add a toolbar button that runs the macro.

Outlook 2010. Follow these instructions to add the macro to the QAT.

Export Outlook Folders to the File System


I stumbled across a question on Experts-Exchange asking if there’s a way to copy/move an Outlook folder to a folder in the file system. The author would like to drag-and-drop the Outlook folder to the file system folder, but notes that while Outlook allows you to drag a message from Outlook to the file system it does not allow you to do the same with a folder. While I’m not aware of any way to do this via dragging and dropping, it’s easy enough to script a solution that allows a user to select a folder and have it copied/moved to the file system. Here’s my solution.
Continue reading