Understanding the Object Browser

dhancy

Board Regular
Joined
Jul 10, 2013
Messages
105
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
 

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Zack Barresse

MrExcel MVP
Joined
Dec 9, 2003
Messages
10,881
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
  3. Web
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.
 

dhancy

Board Regular
Joined
Jul 10, 2013
Messages
105
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.
 

Zack Barresse

MrExcel MVP
Joined
Dec 9, 2003
Messages
10,881
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
  3. Web
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,832
Messages
5,598,358
Members
414,233
Latest member
WolverineNurse

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
Top