Suddenly macro doesn't work

L

Lucian Sitwell

This macro previously worked without any problem. Yesterday, when
installing a new Palm Zire, the contacts got accidentally deleted, but I had
them backed up. Now this macro doesn't work. This macro accesses
information in outlook from word.

I get a type 13 error mismatch at the line: Set objItem =
objContacts.Items.Item(1)

Any ideas what changed??????

Using Office 2003 on a Dell 600M.

Lucian Sitwell

=================================
Sub test2()
'
' test2 Macro
' Macro created 1/4/2005 by Lucian Sitwell
'

' Test Macro
' Macro recorded 12/15/2004 by Lucian Sitwell
'
Dim olApp As Outlook.Application
Dim objContact As Object
Dim objContacts As Outlook.MAPIFolder
Dim objNameSpace As Outlook.NameSpace
Dim objAddress As Object
Dim objInspector As Outlook.Inspector
Dim objExplorer As Outlook.Explorer
Dim objItem As Outlook.ContactItem
Dim strSalutation As String

'Create an instance of Outlook
Set olApp = CreateObject("outlook.application")
Set objNameSpace = olApp.GetNamespace("MAPI")
'Sets up a folder of contacts
Set objContacts = objNameSpace.GetDefaultFolder(olFolderContacts)
'Finds a specific record in Contacts
Set objContact = objContacts.Items.Find("[FullName] = ""Dr. Steven T.
Bencze""")
Set objInspector = olApp.ActiveInspector
Set objItem = objContacts.Items.Item(1)

'If the NickName field isn't blank, then write Dear + nickname
'Otherwise, write Dear Title + Last Name
If objContact.NickName <> "" Then
strSalutation = "Dear " & objContact.NickName & ", "
Else
strSalutation = "Dear " & objContact.Title & " " &
objContact.LastName & ": "
End If
Selection.TypeText objContact.FullName
Selection.TypeParagraph
Selection.TypeText objContact.MailingAddress
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeText Text:=strSalutation & vbCr & vbCr
End Sub
 
L

Lucian Sitwell

My macro started working again when I changed the following statement:

Dim objItem As Outlook.ContactItem

to

Dim objItem

Just so I don't make the same mistake again:

Why did it work previously, even with the "Dim objItem As
Outlook.ContactItem"

Lucian
 
K

Ken Slovak - [MVP - Outlook]

Could item #1 be a distribution list? That can be in a Contacts folder too,
along with Contact items. It's best policy to either check for an error and
handle it after the assignment or by assigning the item to an Object first,
then testing item.Class for olContact before assigning it to a ContactItem
object.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top