Need Help with Script. Keep getting Runtime Error 438

Status
Not open for further replies.

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")
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
Marc2019 Need help please! Cannot Setup my outlook email account on my Mac Outlook 2011 Using Outlook.com accounts in Outlook 2
C need help setting up outlook first time Using Outlook 1
N Need help syncing contacts to iPhone X Using Outlook 8
S Error using AddressEntry.GetContact - need help Outlook VBA and Custom Forms 2
EaglePI Outlook 2010 need help with rules Using Outlook 0
B Need Help - Willing to pay Outlook VBA and Custom Forms 10
J Need Help with Contacts VBA Outlook VBA and Custom Forms 1
H Need help setting up GetFolderPath-Makro with Vodafone IMAP Mail-Account Outlook VBA and Custom Forms 0
T Need help with finding/updating task Outlook VBA and Custom Forms 1
Denis Hi everyone!!! Need some help with Excel to Exchange Calendar??PLEASE>>> Using Outlook 1
E Need Help on Setting up a repeated Reminder on Task with Reoccurence Every Year Using Outlook 6
B Need Help Creating Email Based on Subject w Address in Body Outlook VBA and Custom Forms 1
G Need help configuring a PRF for Outlook 2010 and 2013 Using Outlook 0
K Excel Import Option: Need Help Updating Existing Records BCM (Business Contact Manager) 0
K Need help concerning emails linking to BCM. BCM (Business Contact Manager) 0
J Need help with installation of BCM in Outlook2013 BCM (Business Contact Manager) 5
F Outlook 2010 - Need help with a custom field. Using Outlook 3
R Need help getting BCM to work with my Outlook 2014 Using Outlook 4
L Need help getting calendar/contacts/tasks/notes back! Using Outlook 3
R [VBA] complicated(?) outlook events - need help with code Using Outlook 15
P Need help/Gmail accounts show separately/Outlook 2013 Using Outlook 0
J Need Help Extracting Email Content into Excel Specifically the Attachment Name Using Outlook 3
A Need Help with BCM2010 Sharing on outlook 2013 Scenario! BCM (Business Contact Manager) 1
C Need Help with Simple Code Correction Using Outlook 11
W I Need help with vb.net and outlook 2010 Using Outlook 2
A My move to MS is not going too well: Need Help !!! Using Outlook 14
M Need help with combo boxes in messages! Using Outlook 10
D Need help understanding which pst-file to use! Using Outlook 0
U Need a help please Outlook 2007 crashing Using Outlook 2
Z Need Help Outlook 2007 inbox and address book view Using Outlook 2
B Need help adding a background color to the compact list items in Month view. Calendar Printing Assistant 1
B Need help adding an image next to the Month Name in the header. Calendar Printing Assistant 1
B Ok - a complicated one - but really need help (auto formatting) Using Outlook 9
B OUTLOOK 2000, Need Help ! Outlook Wishlist 1
P To Use BCM or not...I need help BCM (Business Contact Manager) 1
T Need help making RULE to prepend email SUBJECT Using Outlook 3
V Need help on configuring Outook 2003 Rules and Alerts... Using Outlook 2
A Need Help Urgent !!!- Add Seconde Node To The DAG Exchange Server Administration 12
M Need help w/ Calendar Events not appearing in Outlook 2010 Using Outlook 1
D Need help bulk exporting mailboxes Exchange Server Administration 3
G Need help in merging data from multiple .pst data files into one .pst file. Using Outlook 3
L Windows Instant Search Indexing not working need help reading Event Log Using Outlook 2
J i need help regarding error message, 'Addin fax extention' issues in oulook 2007. Using Outlook 3
X business owner in dire need of help outlook is not syncin my contacts! Using Outlook.com accounts in Outlook 2
D Need email verification for international emails, help? BCM (Business Contact Manager) 2
S MAcro - Need help in getting the recipients in to filed / cc field toput in an array Outlook VBA and Custom Forms 4
K Need help Publishing a new Task form! Outlook VBA and Custom Forms 1
A Need help in creating a mass emailing plugin Outlook VBA and Custom Forms 1
T need help w/ sending an e-mail -- outlook 2007 addin Outlook VBA and Custom Forms 2
J Moved many emails to Outlook external folder, need to delete on Gmail server Using Outlook 14

Similar threads

Top