Understanding the Object Browser

dhancy

Board Regular
Joined
Jul 10, 2013
Messages
120
Office Version
  1. 2016
Platform
  1. Windows
Hello,

Within Excel VBA, I am looking at the Object Browser. I have selected Outlook as the Library, and ContactItem as the Class.

Beneath this window is this note:

Class ContactItem
Member of Outlook

Here is the code I am trying to run:
VBA Code:
Dim o As Outlook.Application
Dim c As Outlook.ContactItem
Set o = CreateObject("Outlook.application")
Set c = o.ContactItem

When I step through the code, it produces this error message on the last line:

Run-time error: '438':
Object doesn't support this property or method

If ContactItem is a member of Outlook, how come I am getting this error?

Perhaps I am just not clear on the terms Class, Member, Property and Method. Or perhaps I am not clear how to interpret the information in the Object Browser.


In any case, can anyone shed some light on what I am doing wrong?


Thanks!

Dennis
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
You aren't creating the object correctly. You need to use the CreateItem method to do so. Instead use....

VBA Code:
    Dim OutlookApplication As Outlook.Application
    Dim OutlookContact As Outlook.ContactItem
    Set OutlookApplication = CreateObject("Outlook.Application")
    Set OutlookContact = OutlookApplication.CreateItem(olContactItem) '2

While the Object Browser is helpful, it's not as helpful as documentation. These are what you need to read:

ContactItem object (Outlook)
OlItemType enumeration (Outlook)

Edit: for future reference, I would suggest creating your post titles with a little more clarity in regards to your question.
 
Upvote 0
Thanks Sir.
That works much better.

While I've written plenty of VBA code in the past, I rarely am asked to write code for Outlook. The learning curve for me is learning about the Outlook objects and hierarchies. Part of my research included checking into the Object Browser which mostly just contributed to my confusion. So my questions are about both topics, even though my initial question was about Outlook objects.
 
Upvote 0
Fair enough. Glad it got you sorted. I've been in your position. slipstick.com is probably the best Outlook VBA site I've used over the years. Also, as linked in my previous post, the online documentation is actually pretty darn good. I use it extensively and highly recommend it.
 
Upvote 0

Forum statistics

Threads
1,214,588
Messages
6,120,409
Members
448,959
Latest member
camelliaCase

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top