Need Help with Script. Keep getting Runtime Error 438

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
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
does it highlight any specific line?

Is oContact.ClientId a custom field? You might need to do something like oContact.UserProperties("ClientId").

I have to go to the grocery store and don't have time to test it right now, I'm not totally sure that is correct format, but it's close.
 

DemetriaBeth

Member
Outlook version
Outlook 2013 32 bit
Email Account
Exchange Server
does it highlight any specific line?

Is oContact.ClientId a custom field? You might need to do something like oContact.UserProperties("ClientId").

I have to go to the grocery store and don't have time to test it right now, I'm not totally sure that is correct format, but it's close.
Thanks for the reply Diane. Yes! It is a custom field and that is the one that was highlighted! I will try this and let you know how it turns out.
 

DemetriaBeth

Member
Outlook version
Outlook 2013 32 bit
Email Account
Exchange Server
Hi Diane....

I redid the script and now I'm getting different errors. This is what I have:

Code:
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:\"Public Sub SendAddressToWord()'Dim oContact 
 
If TypeName(ActiveExplorer.Selection.Item(1)) = "ContactItem" Then 
 
Set oContact = ActiveExplorer.Selection.Item(1) 
 
The colored words it says syntax error.
  ' 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\Documents\PrepareChecklist"
  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.oContact.UserProperties("ClientId")
     
    .Selection.GoTo What:=wdGoToBookmark, Name:="Address1"
    .Selection.TypeText Text:=oContact.UserProperties("Address1")
 
    .Selection.GoTo What:=wdGoToBookmark, Name:="City1"
    .Selection.TypeText Text:=oContact.UserProperties("City1")
    .Selection.GoTo What:=wdGoToBookmark, Name:="State1"
    .Selection.TypeText Text:=oContact.UserProperties("State1")

    .Selection.GoTo What:=wdGoToBookmark, Name:="ZipCode"
    .Selection.TypeText Text:=oContact.UserProperties("ZipCode")
    .Selection.GoTo What:=wdGoToBookmark, Name:="Email2"
    .Selection.TypeText Text:=oContact.UserProperties("Email2")
    .Selection.GoTo What:=wdGoToBookmark, Name:="PrimaryPhone"
    .Selection.TypeText Text:=oContact.UserProperties("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
  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.oContact.UserProperties("ClientId")
     
    .Selection.GoTo What:=wdGoToBookmark, Name:="Address1"
    .Selection.TypeText Text:=oContact.UserProperties("Address1")
 
    .Selection.GoTo What:=wdGoToBookmark, Name:="City1"
    .Selection.TypeText Text:=oContact.UserProperties("City1")
    .Selection.GoTo What:=wdGoToBookmark, Name:="State1"
    .Selection.TypeText Text:=oContact.UserProperties("State1")

    .Selection.GoTo What:=wdGoToBookmark, Name:="ZipCode"
    .Selection.TypeText Text:=oContact.UserProperties("ZipCode")
    .Selection.GoTo What:=wdGoToBookmark, Name:="Email2"
    .Selection.TypeText Text:=oContact.UserProperties("Email2")
    .Selection.GoTo What:=wdGoToBookmark, Name:="PrimaryPhone"
    .Selection.TypeText Text:=oContact.UserProperties("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
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Are all of these custom fields? plus, you have ocontact in twice in the clientid line.

> Selection.GoTo What:=wdGoToBookmark, Name:="ClientId"
.Selection.TypeText Text:=oContact.oContact.UserProperties("ClientId")
.Selection.GoTo What:=wdGoToBookmark, Name:="Address1"
.Selection.TypeText Text:=oContact.UserProperties("Address1")
.Selection.GoTo What:=wdGoToBookmark, Name:="City1"
.Selection.TypeText Text:=oContact.UserProperties("City1")
.Selection.GoTo What:=wdGoToBookmark, Name:="State1"
.Selection.TypeText Text:=oContact.UserProperties("State1")
.Selection.GoTo What:=wdGoToBookmark, Name:="ZipCode"
.Selection.TypeText Text:=oContact.UserProperties("ZipCode")
.Selection.GoTo What:=wdGoToBookmark, Name:="Email2"
.Selection.TypeText Text:=oContact.UserProperties("Email2")
.Selection.GoTo What:=wdGoToBookmark, Name:="PrimaryPhone"
.Selection.TypeText Text:=oContact.UserProperties("PrimaryPhone")
 

Top