A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Object declarations



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old September 9th 08, 06:33 PM posted to microsoft.public.outlook.program_vba
Sierk
external usenet poster
 
Posts: 12
Default Object declarations

Hi,

I have gotten my customization for Outlook to work (VB) for the most part,
and I am trying to clean things up. I am challenged by the declaration of
object variables. I get an error on the following line of code (Option
Explicit is set)

Set myItem = ActiveExplorer.Selection.Item(1)

With the following declaration

Dim myItem As Outlook.Explorer

If I declare myItem as Variant it works fine. I just would like to know
what the proper declaration for these types of object variables is. I am
having similar problems with Word Document Objects. Also if there is a good
white paper describing declaration of variables in this environment I'd much
like to know its location.

Thanks

--
Sierk
Ads
  #2  
Old September 9th 08, 07:02 PM posted to microsoft.public.outlook.program_vba
Sierk
external usenet poster
 
Posts: 12
Default Object declarations

Sorry, forgot to mention that I am working in Outlook 2007.
--
Sierk


"Sierk" wrote:

Hi,

I have gotten my customization for Outlook to work (VB) for the most part,
and I am trying to clean things up. I am challenged by the declaration of
object variables. I get an error on the following line of code (Option
Explicit is set)

Set myItem = ActiveExplorer.Selection.Item(1)

With the following declaration

Dim myItem As Outlook.Explorer

If I declare myItem as Variant it works fine. I just would like to know
what the proper declaration for these types of object variables is. I am
having similar problems with Word Document Objects. Also if there is a good
white paper describing declaration of variables in this environment I'd much
like to know its location.

Thanks

--
Sierk

  #3  
Old September 9th 08, 07:32 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Object declarations

Dim myItem As Outlook.Explorer

Set myItem = ActiveExplorer

The items in a Selection collection can be anything, depending on the item
and the folder. For example a contacts folder could hold contacts as well as
distribution lists. Inbox can hold meeting or task requests, NDR's, etc. in
addition to email or post items.

So usually what one does for an item like that is declare it as Object and
test it to see what type of object before early binding it to a specific
type such as MailItem. I usually test for item.Class for that.

The Object Browser is the invaluable tool for seeing object declarations,
types, method signatures, etc.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Sierk" wrote in message
...
Hi,

I have gotten my customization for Outlook to work (VB) for the most part,
and I am trying to clean things up. I am challenged by the declaration of
object variables. I get an error on the following line of code (Option
Explicit is set)

Set myItem = ActiveExplorer.Selection.Item(1)

With the following declaration

Dim myItem As Outlook.Explorer

If I declare myItem as Variant it works fine. I just would like to know
what the proper declaration for these types of object variables is. I am
having similar problems with Word Document Objects. Also if there is a
good
white paper describing declaration of variables in this environment I'd
much
like to know its location.

Thanks

--
Sierk


  #4  
Old September 9th 08, 08:11 PM posted to microsoft.public.outlook.program_vba
Sierk
external usenet poster
 
Posts: 12
Default Object declarations

Thanks Ken, but I think I am going to need a bit more. I checked out the
item.class object property and it returned 34. How do I find the appropriate
constants representing the values. In my case a Contact Item.

Then also, How do I access the properties like "Account" since
strAccount = myItem.Account
no longer works?
--
Sierk


"Ken Slovak - [MVP - Outlook]" wrote:

Dim myItem As Outlook.Explorer

Set myItem = ActiveExplorer

The items in a Selection collection can be anything, depending on the item
and the folder. For example a contacts folder could hold contacts as well as
distribution lists. Inbox can hold meeting or task requests, NDR's, etc. in
addition to email or post items.

So usually what one does for an item like that is declare it as Object and
test it to see what type of object before early binding it to a specific
type such as MailItem. I usually test for item.Class for that.

The Object Browser is the invaluable tool for seeing object declarations,
types, method signatures, etc.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Sierk" wrote in message
...
Hi,

I have gotten my customization for Outlook to work (VB) for the most part,
and I am trying to clean things up. I am challenged by the declaration of
object variables. I get an error on the following line of code (Option
Explicit is set)

Set myItem = ActiveExplorer.Selection.Item(1)

With the following declaration

Dim myItem As Outlook.Explorer

If I declare myItem as Variant it works fine. I just would like to know
what the proper declaration for these types of object variables is. I am
having similar problems with Word Document Objects. Also if there is a
good
white paper describing declaration of variables in this environment I'd
much
like to know its location.

Thanks

--
Sierk



  #5  
Old September 9th 08, 08:31 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Object declarations

Again, use the Object Browser.

If you look up say ContactItem.Class it points you to the OlObjectClass
enumeration, where you find that 34 is equal to Explorer.

Now since you can't get an Explorer from ActiveExplorer.Selection.Item(1) I
have no idea where you're reading item.Class from but it certainly is not
from Selection.Item(1).

A ContactItem is class 40 (olContact).

Account is an string property on a ContactItem object. So strAccount =
item.Account is valid only for contact items. For a MailItem you can use
item.SendUsingAccount, which returns an Account object, not a string. All of
your accounts are in the NameSpace.Accounts collection, which is a
collection of Accounts.

All of this information I just got from the Object Browser.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Sierk" wrote in message
...
Thanks Ken, but I think I am going to need a bit more. I checked out the
item.class object property and it returned 34. How do I find the
appropriate
constants representing the values. In my case a Contact Item.

Then also, How do I access the properties like "Account" since
strAccount = myItem.Account
no longer works?
--
Sierk


  #6  
Old September 10th 08, 03:45 PM posted to microsoft.public.outlook.program_vba
Sierk
external usenet poster
 
Posts: 12
Default Object declarations

Thanks Ken,
As you can see the Object browser is pretty new to me, and I find it
difficult to use especially since it only provides the cursory relationship
information. Perhaps I’ll get used to it after using it a while.

The following is what I started with, and believe it or not it works. For
clarification, I invoke the function after I have selected a contact (or made
it active) from the contact list. The idea is to create a preformatted
address text block that can be inserted in letters envelopes etc.

Sub GetContactAddressData()
Dim myItem As Outlook.ContactItem
Dim strName As String

'Select active address card (Explorer Item)
Set myItem = ActiveExplorer.Selection.Item(1)

If myItem Is Nothing Then
MsgBox "Please select a Contact item before running this function."
GoTo ExitProc
End If

'Collect personal information from the contact item
strName = myItem.Account
Etc.

I think the reason my class was returning 34 before was because I specified
an explorer object when I tried what you suggested as follows.

Dim myItem As Outlook.Explorer
Set myItem = ActiveExplorer
MsgBox myItem.Class

To access the active Contact, according to the object library I would have
to use the application class. But I am not sure how to select the active
contact window using the application class. Can you suggest how to do that?

--
Sierk

  #7  
Old September 10th 08, 03:58 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Object declarations

ActiveInspector is the currently active item window (Inspector).

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Sierk" wrote in message
...
Thanks Ken,
As you can see the Object browser is pretty new to me, and I find it
difficult to use especially since it only provides the cursory
relationship
information. Perhaps I’ll get used to it after using it a while.

The following is what I started with, and believe it or not it works. For
clarification, I invoke the function after I have selected a contact (or
made
it active) from the contact list. The idea is to create a preformatted
address text block that can be inserted in letters envelopes etc.

Sub GetContactAddressData()
Dim myItem As Outlook.ContactItem
Dim strName As String

'Select active address card (Explorer Item)
Set myItem = ActiveExplorer.Selection.Item(1)

If myItem Is Nothing Then
MsgBox "Please select a Contact item before running this function."
GoTo ExitProc
End If

'Collect personal information from the contact item
strName = myItem.Account
Etc.

I think the reason my class was returning 34 before was because I
specified
an explorer object when I tried what you suggested as follows.

Dim myItem As Outlook.Explorer
Set myItem = ActiveExplorer
MsgBox myItem.Class

To access the active Contact, according to the object library I would have
to use the application class. But I am not sure how to select the active
contact window using the application class. Can you suggest how to do
that?

--
Sierk


  #8  
Old September 10th 08, 04:40 PM posted to microsoft.public.outlook.program_vba
Sierk
external usenet poster
 
Posts: 12
Default Object declarations

Ken,

If ActiveInspector is the active item window then how do I extract the
contact information. I don't see anything in the object browser that I can
use to get to the contact information. Also, It would probably help a lot
if you had some sample code so I can see the big picture. I find it
extremely challenging working in an environment that gives you nothing but
little puzzle pieces, as much as I like puzzles and games.
--
Sierk


"Ken Slovak - [MVP - Outlook]" wrote:

ActiveInspector is the currently active item window (Inspector).

--
Ken Slovak


  #9  
Old September 10th 08, 09:46 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Object declarations

The Object Browser help does have lots of code samples and snippets on
almost every property/method/event that's available you know. Just press F1
on a property to get to that.

For ActiveInspector. Every Inspector has a CurrentItem property that returns
the item being displayed in the Inspector. So if you only want contact items
this code snippet would work:

Dim obj As Object
Set obj = ActiveInspector.CurrentItem
If obj.Class = OlObjectClass.OlContact Then
' a contact item
Dim oContact As Outlook.ContactItem
Set oContact = obj
' now get to contact properties
Else
' not a contact
MsgBox "This is not a contact"
End If

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Sierk" wrote in message
...
Ken,

If ActiveInspector is the active item window then how do I extract the
contact information. I don't see anything in the object browser that I
can
use to get to the contact information. Also, It would probably help a
lot
if you had some sample code so I can see the big picture. I find it
extremely challenging working in an environment that gives you nothing but
little puzzle pieces, as much as I like puzzles and games.
--
Sierk


  #10  
Old September 11th 08, 05:33 PM posted to microsoft.public.outlook.program_vba
Sierk
external usenet poster
 
Posts: 12
Default Object declarations

Thanks Ken,
Use of the object browser is beginning to make sense. The following code is
what I am using to test your suggestions. With it I get an error, '91' see
below, on the "Set obj = ActiveInspector.CurrentItem" line of code. Can you
tell me what I am missing? Also does it matter if variables, oContact in
particular, are declared in the code, after the if then as you did in the
sample you gave me, or at the beginning of the subroutine as I prefer to do?

Public Sub GetContactTitleData()
Dim obj As Object
Dim oContact As Outlook.ContactItem

Set obj = ActiveInspector.CurrentItem
If obj.Class = OlObjectClass.olContact Then
' a contact item
Set oContact = obj
MsgBox oContact.Account
Else
' not a contact
MsgBox "This is not a contact"
End If
End Sub

Run-time Error '91': Object variable or With block variable not set
--
Sierk


"Ken Slovak - [MVP - Outlook]" wrote:

The Object Browser help does have lots of code samples and snippets on
almost every property/method/event that's available you know. Just press F1
on a property to get to that.

For ActiveInspector. Every Inspector has a CurrentItem property that returns
the item being displayed in the Inspector. So if you only want contact items
this code snippet would work:

Dim obj As Object
Set obj = ActiveInspector.CurrentItem
If obj.Class = OlObjectClass.OlContact Then
' a contact item
Dim oContact As Outlook.ContactItem
Set oContact = obj
' now get to contact properties
Else
' not a contact
MsgBox "This is not a contact"
End If

--
Ken Slovak


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CPAO: object reference not set to an instance of an object Caroline Outlook - Calandaring 2 November 29th 08 05:32 AM
Use Treeview object Boein Outlook - Using Forms 0 June 10th 08 11:51 AM
Why does the Address property of the Recipient object in the Outlook object model look funny? Omatase Outlook - General Queries 2 July 13th 07 10:09 PM
Object reference not set to an instance of an object [email protected] Outlook - General Queries 0 May 17th 07 08:40 AM
VBE Object for Outlook Dave Miller Outlook and VBA 8 January 31st 07 06:02 PM


All times are GMT +1. The time now is 08:54 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.