A code that adds category to an outgoing mail message in outlook

N

newED

This code adds a category name to an outgoing mail message in outlook.
However when using it - the subject disappears. Do you happen to know
why and how to fix it ?

Public Sub TagMessage()
Set objOL = CreateObject("Outlook.Application")
If Not objOL.ActiveInspector Is Nothing Then
Set objItem = objOL.ActiveInspector.CurrentItem
objItem.Categories = "my category"
End If
End Sub

Thanks for your help
 
K

Ken Slovak - [MVP - Outlook]

There's no reason I can see for subject to become blank.

If this is running in the Outlook VBA project use Application and don't ever
use CreateObject or New:

If Not Application.ActiveInspector Is Nothing Then

etc.
 
S

Simon Lloyd

For everything you need to know on sending mail take a look her
'Example Code for sending mail from Excel
(http://www.rondebruin.nl/sendmail.htm

newED;438449 said:
This code adds a category name to an outgoing mail message in outlook
However when using it - the subject disappears. Do you happen to kno
why and how to fix it ?

Public Sub TagMessage(
Set objOL = CreateObject("Outlook.Application"
If Not objOL.ActiveInspector Is Nothing The
Set objItem = objOL.ActiveInspector.CurrentIte
objItem.Categories = "my category
End I
End Su

Thanks for your hel

--
Simon Lloy

Regards
Simon Lloy
'Microsoft Office Help' (http://www.thecodecage.com
 
N

newED

thank Ken,

unfortunately, it does get blank everytime I use this code.

Btw, I tried your offered suggestion. However I'm not quite sure I
understood it, because now I get a compile error:
" Method or data not found" - with the new code line highlighted

should I make anymore changes in the code so that your offered change
would work?

Thanks

'Ken Slovak - [MVP - Outlook said:
;438482']There's no reason I can see for subject to become blank.

If this is running in the Outlook VBA project use Application and don't
ever
use CreateObject or New:

If Not Application.ActiveInspector Is Nothing Then

etc.

--
Ken Slovak
[MVP - Outlook]
'Slovak Technical Services Home' (http://www.slovaktech.com)
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
'Slovak Technical Services Products'
(http://www.slovaktech.com/products.htm)


newED said:
This code adds a category name to an outgoing mail message in outlook.
However when using it - the subject disappears. Do you happen to know
why and how to fix it ?

Public Sub TagMessage()
Set objOL = CreateObject("Outlook.Application")
If Not objOL.ActiveInspector Is Nothing Then
Set objItem = objOL.ActiveInspector.CurrentItem
objItem.Categories = "my category"
End If
End Sub

Thanks for your help


--
newED
------------------------------------------------------------------------
newED's Profile: 'The Code Cage Forums - View Profile: newED' (http://www.thecodecage.com/forumz/member.php?userid=603)
View this thread:
'A code that adds category to an outgoing mail message in outlook -
The Code Cage Forums'
(http://www.thecodecage.com/forumz/showthread.php?t=121671)
 
K

Ken Slovak - [MVP - Outlook]

The suggestion I made was only if the code is running in the Outlook VBA
project, not in Excel or some other application. Is the code running in
Outlook? If not then go back to using CreateObject().

Unless there's additional code you haven't shown, the code you did show does
nothing to touch Subject so I can't see how the subject would be blanked.
 
N

newED

'Ken Slovak - [MVP - Outlook said:
;439563']The suggestion I made was only if the code is running in the
Outlook VBA
project, not in Excel or some other application. Is the code running
in
Outlook? If not then go back to using CreateObject().

Unless there's additional code you haven't shown, the code you did show
does
nothing to touch Subject so I can't see how the subject would be
blanked.

--
Ken Slovak
[MVP - Outlook]
'Slovak Technical Services Home' (http://www.slovaktech.com)
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
'Slovak Technical Services Products'
(http://www.slovaktech.com/products.htm)


newED said:
thank Ken,

unfortunately, it does get blank everytime I use this code.

Btw, I tried your offered suggestion. However I'm not quite sure I
understood it, because now I get a compile error:
" Method or data not found" - with the new code line highlighted

should I make anymore changes in the code so that your offered change
would work?

Thanks



I found a different way to overcome this problem, withoutthe creating a
new object.
Anyway, it sloved my problem.
Thanks
 
N

newED

Simon said:
Glad you're sorted, if possible post your solution here to aid others
in any case:

off-course.

I used this simple code insteadץ
Apparently, it does the same thing in a much simpler way

Public Sub TagMessage()
ActiveInspector.CurrentItem.Categories = "ZZZ"
End Su
 

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