DemetriaBeth
Member
- Outlook version
- Outlook 2013 32 bit
- Email Account
- Exchange Server
I have used the script that diane had in her article "Create A Letter to A Contact Using VBA". I supplied the fields that I needed, but I must be doing something wrong. I got the Compile error first, so in References I Click word object and now I am getting this runtime 438 error. Would someone mind taking a look at the script and tell me where I'm going wrong? Thanks!
Public Sub SendAddressToWord()
'Dim oContact
If TypeName(ActiveExplorer.Selection.Item(1)) = "ContactItem" Then
Set oContact = ActiveExplorer.Selection.Item(1)
' Declare the variable.
Dim oWord As Word.Application
' Set the variable (runs new instance of Word).
Set oWord = CreateObject("Word.Application")
oWord.Documents.Add Template:="C:\Users\Beth\AppData\Roaming\Microsoft\Templates\Preparer Checklist"
With oWord
' Find the bookmark, insert an Outlook field
.Selection.GoTo What:=wdGoToBookmark, Name:="FullName"
.Selection.TypeText Text:=oContact.FullName
.Selection.GoTo What:=wdGoToBookmark, Name:="ClientId"
.Selection.TypeText Text:=oContact.ClientId
.Selection.GoTo What:=wdGoToBookmark, Name:="Address1"
.Selection.TypeText Text:=oContact.Address1
.Selection.GoTo What:=wdGoToBookmark, Name:="City1"
.Selection.TypeText Text:=oContact.City1
.Selection.GoTo What:=wdGoToBookmark, Name:="State1"
.Selection.TypeText Text:=oContact.State1
.Selection.GoTo What:=wdGoToBookmark, Name:="ZipCode"
.Selection.TypeText Text:=oContact.ZipCode
.Selection.GoTo What:=wdGoToBookmark, Name:="Email2"
.Selection.TypeText Text:=oContact.Email2
.Selection.GoTo What:=wdGoToBookmark, Name:="PrimaryPhone"
.Selection.TypeText Text:=oContact.PrimaryPhone
' Show the Word document
.Visible = True
End With
' Clear the variable from memory.
Set oWord = Nothing
Else
MsgBox "Sorry, you need to select a contact"
End If
End Sub
Public Sub SendAddressToWord()
'Dim oContact
If TypeName(ActiveExplorer.Selection.Item(1)) = "ContactItem" Then
Set oContact = ActiveExplorer.Selection.Item(1)
' Declare the variable.
Dim oWord As Word.Application
' Set the variable (runs new instance of Word).
Set oWord = CreateObject("Word.Application")
oWord.Documents.Add Template:="C:\Users\Beth\AppData\Roaming\Microsoft\Templates\Preparer Checklist"
With oWord
' Find the bookmark, insert an Outlook field
.Selection.GoTo What:=wdGoToBookmark, Name:="FullName"
.Selection.TypeText Text:=oContact.FullName
.Selection.GoTo What:=wdGoToBookmark, Name:="ClientId"
.Selection.TypeText Text:=oContact.ClientId
.Selection.GoTo What:=wdGoToBookmark, Name:="Address1"
.Selection.TypeText Text:=oContact.Address1
.Selection.GoTo What:=wdGoToBookmark, Name:="City1"
.Selection.TypeText Text:=oContact.City1
.Selection.GoTo What:=wdGoToBookmark, Name:="State1"
.Selection.TypeText Text:=oContact.State1
.Selection.GoTo What:=wdGoToBookmark, Name:="ZipCode"
.Selection.TypeText Text:=oContact.ZipCode
.Selection.GoTo What:=wdGoToBookmark, Name:="Email2"
.Selection.TypeText Text:=oContact.Email2
.Selection.GoTo What:=wdGoToBookmark, Name:="PrimaryPhone"
.Selection.TypeText Text:=oContact.PrimaryPhone
' Show the Word document
.Visible = True
End With
' Clear the variable from memory.
Set oWord = Nothing
Else
MsgBox "Sorry, you need to select a contact"
End If
End Sub