Word 2003 and Outlook 2007 macro Run Time Error 13

F

Fred

Run Time Error 13 Type Mismatch with Word 2003 and Outlook 2007? Does anyone
know what the problem is here? Help gives a variety of Debug Error etc but
nothing I can see? It worked fine the other day!!
At a loss...

Option Explicit

Private Sub UserForm_Initialize()

Dim objOL As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objFolder As MAPIFolder
Dim c As Outlook.ContactItem

Set objOL = New Outlook.Application
Set objNS = objOL.GetNameSpace("MAPI")
Set objFolder = objNS.GetDefaultFolder(olFolderContacts)
For Each c In objFolder.Items
ComboBox1.AddItem c.FullName & " - " & c.Email1Address
Next
ComboBox1.ListIndex = 0

Set objOL = Nothing

End Sub

Private Sub cmdInsert_Click()

Selection.TypeText ComboBox1.SelText

End Sub

Private Sub cmdClose_Click()
Unload Me
End Sub
 
P

Perry

At first glance, nothing wrong with the code there...
So I copied the code and recreated the userform, and still not
able to reproduce ....

When y're in a session (in which this code fails) have you tried to step
through yr code in order to locate the offending VBA statement??

Krgrds,
Perry
 
P

Perry

ComboBox1.AddItem c.FullName & " - " & c.Email1Address

Still not able to reproduce but:
The above line will most definitely be the heartbreaker ...

Try to pass c.FullName and c.Email1Address to a seperate variable
of type String. Do the concatenation of both strings into another variable
of type String and AddItem the combined variable to ComboBox1

Krgrds,
Perry
 
G

Graham Mayor

Have you added the Outlook 2007 object library to Word's vba - if indeed it
is available to add?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
P

Perry

He wouldn't even get to the 13 Mismatch error, instead the VBA compiler
throws in "User Defined Type Unknown" or "Function Not Recognised" error
messages.

So you can fairly assume a reference to Outlook being set.

Krgrds,
Perry
 

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