Simple assign category button

G

Guest

Hi, this is my very first attempt at programming anything in outlook.

Since assigning categories when sending mails are so well hidden (you have
to click at least 5-6 times to assign one to an outgoing message) I want to
create a button with code that assigns a certain category to the outgoing
message.

I know that I have to use the objMail.Categories property and to save it by
objMail.Save. But do I have to do something initially in the code to get it
working?

Basically what I have so far is:

If objMail.Categories = "" Then
objMail.Categories = "Privat"
objMail.Save
Else
objMail.Categories = ""
objMail.Save
End If
End Sub

But I guess that even though I am running the macro in the current mail
window it does not compute which to initialize.

Any help
 
S

Sue Mosher [MVP-Outlook]

The item currently being displayed is Application.ActiveInspector.CurrentItem. Thus:

Set objMail = Application.ActiveInspector.CurrentItem
If objMail.Categories = "" Then
objMail.Categories = "Privat"
objMail.Save
End If

You don't need the Else block at all.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
G

Guest

Hello

Thank you for the quick reply. :)

It doesn't seem like it wants to accept the .ActiveInspector. part of the
code. Is there any workaround for that?

The else part was mostly to remove the category again if someone
accidentally pressed it.

thanks
 
S

Sue Mosher [MVP-Outlook]

OK, I understand what you were trying to do with the Else part.

Where are you writing this code -- in Outlook VBA or in Word VBA?
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP-Outlook]

This may sound dumb, but are you sure you're not working in Word VBA? If you have an OUtlook item open and you put code in OUtlook VBA to work with Application.ActiveInspector, it will definitely return an Inspector object.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
I

Ian Mackenzie

Hi Sue

I am having a problem, not accessing the categories, but viewing them.

I can access then with the item.categories, but they are always empty
although some have categories assigned to them.

Delphi Code:
-------------

for count := 1 to currentfolder.items.count do
begin
outlookItem := currentfolder.items[count];
safeItem.Item := outlookItem; --> (Redemption
SafeContactItem)

showmessage(safeItem.categories); --> (Always empty string)

Is there anything I am doing serioously wrong?????

Thanks

Ian




This may sound dumb, but are you sure you're not working in Word VBA? If you
have an OUtlook item open and you put code in OUtlook VBA to work with
Application.ActiveInspector, it will definitely return an Inspector object.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP-Outlook]

Ian, what about outlookItem.Categories? You don't need Redemption to access the Categories property.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
I

Ian Mackenzie

Thanks for the reply.

I figured that, but eben without Redemption, I am finding it very hard to
access many field for each Outlook Item Type... Things like CompanyName and
FullName give me -> "Method 'CompanyName' not supported by automation
object."


var
outlookItem: OLEVariant;
begin
for count := 1 to currentFolder.items.count do
begin
outlookItem := currentFolder.items[count];
showmessage(outlookItem.categories);
end;

This code still returns empty string, even if I don't use Redemption, but
every contact does have a category assigned.

Here is a full set of my code:
-----------------------------

for count := 1 to currentFolder.items.count do
begin
outlookItem := currentFolder.items[count];
safeItem.Item := outlookItem;

if ansiContainsStr(safeItem.categories, 'Test Category')
then
begin
Append;
FieldbyName('ID').AsInteger := count;
FieldbyName('ENTRYID').AsString := safeItem.EntryID;
FieldbyName('FIRSTNAME').AsString := safeitem.FirstName;
FieldbyName('LASTNAME').AsString := safeItem.LastName;
FieldbyName('FULLNAME').AsString := safeItem.FullName;
FieldbyName('COMPANYNAME').AsString :=
safeItem.CompanyName;
FieldbyName('EMAIL1ADDRESS').AsString :=
safeItem.EMail1Address;
FieldbyName('EMAIL1ADDRESSTYPE').AsString :=
safeItem.EMail1AddressType;
FieldbyName('EMAIL1DISPLAYNAME').AsString :=
safeItem.EMail1DisplayName;
FieldbyName('EMAIL1ENTRYID').AsString :=
safeItem.EMail1EntryID;
FieldbyName('CATEGORY').AsString := safeItem.categories;
FieldbyName('ICON').AsString := '';
FieldbyName('FILEAS').AsString := safeItem.fileas;
FieldbyName('BUSINESSPHONE').AsString :=
safeItem.businessphone;
FieldbyName('BUSINESSFAX').AsString :=
safeItem.businessfax;
FieldbyName('HOMEPHONE').AsString := safeItem.homephone;
FieldbyName('MOBILEPHONE').AsString :=
safeItem.mobilephone;
FieldbyName('BUSINESSADDRESS').AsString :=
safeItem.businessaddress;
FieldbyName('HOMEADDRESS').AsString :=
safeItem.homeaddress;
FieldbyName('JOBTITLE').AsString := safeItem.jobtitle;
FieldbyName('DEPARTMENT').AsString :=
safeItem.department;
FieldbyName('WEBPAGE').AsString := safeItem.webpage;
Post;
end;
end;





Ian, what about outlookItem.Categories? You don't need Redemption to access
the Categories property.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Ian Mackenzie said:
Hi Sue

I am having a problem, not accessing the categories, but viewing them.

I can access then with the item.categories, but they are always empty
although some have categories assigned to them.

Delphi Code:
-------------

for count := 1 to currentfolder.items.count do
begin
outlookItem := currentfolder.items[count];
safeItem.Item := outlookItem; --> (Redemption
SafeContactItem)

showmessage(safeItem.categories); --> (Always empty string)

Is there anything I am doing serioously wrong?????
 
G

Guest

Well I am doing all the VBA code in Outlook from the macro window. But I am
not sure if I am initializing any outlook items. All the code I have is the
one posted in the first post I made in this thread.

thanks
 
S

Sue Mosher [MVP-Outlook]

But *which* macro window? Just tell us the name of the macro project in VBA.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP-Outlook]

Great, that finally confirms that your code is indeed in the Outlook VBA window. So, you have a statement like this, right, to assign the object variable objMail to a particular item:

Set objMail = Application.ActiveInspector.CurrentItem

Your code needs to handle the case where there is no ActiveInspector. The ideal way to handle that is to check:

Set insp = Application.ActiveInspector
If Not insp Is Nothing Then
Set objMail = insp.CurrentItem
' put all the rest of your objMail code here
End If

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
G

Guest

Lol, sorry to bother again, but after having coded the thing in the outlook
vba I realized that it won't work as the ones used when writing a new mail
message are word vba macros.

Do I need to do anything else because of that??

And what would the code look like?
 
S

Sue Mosher [MVP-Outlook]

The main difference is that the intrinsic Application object in Word VBA is a Word.Application object. Therefore, you need to instantiate an Outlook.Application object like this:

Set outApp = CreateObject("Outlook.Application")

and use that object to get ActiveInspector, etc.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

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