Graham Mayor

... helping to ease the lives of Microsoft Word users.

Many people access the material from this web site daily. Most just take what they want and run. That's OK, provided they are not selling on the material as their own; however if your productivity gains from the material you have used, a donation from the money you have saved would help to ensure the continued availability of this resource. Click the appropriate button above to access PayPal.

Create Outlook entries from a Word document

In the first example you may have a list of events that you wish to insert into Outlook's calendar. This is relatively simple to do, however the first step (required for all the macros on this page) is to add the Outlook object library to Word's vba. This can be located by running the vba editor (ALT+F11) and from Tools > References, check the Outlook entry.

The illustration shows the version for Office 2003.

If you do not know what to do with macro code listings, see my  Idiots Guide to Installing Macros.

The macro assumes that the currently active document is a list of events contained in a three column table with a header row, similar to the example below:

The macro enters each entry in the table (apart from the header row) into Outlook's Calendar and assigns the Category 'Events'.

Sub AddAppntmnt()
'Adds a list of events contained in a three column Word table
'with a header row, to Outlook Calendar
Dim ol As New Outlook.Application
Dim ci As AppointmentItem
Dim ctable As Table
Dim i As Long
Dim strStartDate As Range
Dim strEndDate As Range
Dim strSubject As Range
Set ctable = ActiveDocument.Tables(1)
'Ignore the first (header) row of the table
For i = 2 To ctable.Rows.Count
Set strStartDate = ctable.Cell(i, 1).Range
strStartDate.End = strStartDate.End - 1
Set strEndDate = ctable.Cell(i, 2).Range
strEndDate.End = strEndDate.End - 1
Set strSubject = ctable.Cell(i, 3).Range
strSubject.End = strSubject.End - 1
Set ci = ol.CreateItem(olAppointmentItem)
ci.Start = strStartDate
ci.End = strEndDate
ci.ReminderSet = False
ci.AllDayEvent = True
ci.Subject = strSubject
ci.Categories = "Events"
ci.BusyStatus = olFree
ci.Save
Set ol = Nothing
Next i
End Sub

 

Add Outlook Task from Word Document

The next example adds a task reminder based on the current document to follow up the document in 10 days with a due date of 14 days. The macro prompts for a category to assign:

Sub AddOutlookTask()
Dim ol As New Outlook.Application
Dim ct As TaskItem
Dim fName As String
Dim flName As String
If ActiveDocument.Saved = False Then
ActiveDocument.Save
End If
Set ct = ol.CreateItem(olTaskItem)
fName = ActiveDocument.Name
flName = ActiveDocument.FullName
ct.Subject = "Follow up " & fName
ct.Body = "If no reply to" & vbCr & _
flName & vbCr & "further action required"
ct.StartDate = Date + 10
ct.DueDate = Date + 14
ct.Importance = olImportanceHigh
ct.Categories = InputBox("Category?", "Categories")
ct.Save
Set ol = Nothing
Exit Sub
UserCancelled:
Set ol = Nothing
End Sub

 

Add Addressee information from a letter to Outlook Contacts

Word provides the means to look up Outlook Contacts to add to the addresses to documents, and an enhanced version of this can be found on the Macrobutton tutorial page, but what if you want to reverse the process and save a typed address back into Outlook as a new contact? The following macro performs that task.

As configured it creates a new business contact. In addition to the company address which the user first selects from the document, an input box asks for the personal contact name (if any). A second input box is provided for category information.

Sub AddOutlookCont()
Dim ol As New Outlook.Application
Dim ci As ContactItem
Dim strAddress As String
Dim strName As String
Dim strFullName As String
Dim strBusiness As String
Dim iSplit As Long
Dim iResult As Long
strAddress = Selection.Range
'error check to establish if an address has been selected
If Len(strAddress) < 1 Then
MsgBox "No address selected!" & vbCr & "Select the address and re-run the macro", vbCritical, "Select Address"
Exit Sub
End If
'Let the user see the selected address is correct
iResult = MsgBox("Is the address correct?" & _
vbCr & vbCr & strAddress, vbYesNo, "Address")
If iResult = 7 Then GoTo UserCancelled:
'Prompt for personal contact details, if known
strFullName = InputBox("Enter contact's full name if known" _
& vbCr & "in the format 'Mr. John Smith", "Contact name")
On Error GoTo UserCancelled:
iSplit = InStr(strAddress, Chr(13))
strName = Left(strAddress, iSplit - 1)
strBusiness = Right(strAddress, (Len(strAddress) - Len(strName)))
Set ci = ol.CreateItem(olContactItem)
ci.MailingAddress = strBusiness
ci.CompanyName = strName
If strFullName <> "" Then ci.FullName = strFullName
ci.FileAs = strName
'Prompt for category
ci.Categories = InputBox("Category?", "Categories")
ci.Save
Set ol = Nothing
Exit Sub
UserCancelled:
MsgBox "User Cancelled or address not selected"
Set ol = Nothing
End Sub

 

 

Outlook from Word

Word users can use the power of Word and vba to create entries in Outlook based upon the content of a Word document.