Hi, I would like to assign a category (already put in Master List) via a macro button on a customised toolbar. I know how to create a toolbar button assigned to a macro, however I dont know how to write VBA code to assign the category. Is this possible?
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Macro to Assign Category (2003)
Home » Forums » AskWoody support » Productivity software by function » MS Outlook and email programs » Macro to Assign Category (2003)
- This topic has 14 replies, 4 voices, and was last updated 18 years, 4 months ago.
Viewing 0 reply threadsAuthorReplies-
WSHansV
AskWoody LoungerNovember 17, 2006 at 8:22 am #1039192If you want to assign a specific category:
Sub SetCategory()
If Inspectors.Count > 0 Then
ActiveInspector.CurrentItem.Categories = “MyCategory”
End If
End SubIf you want to show the Categories dialog, see JohnBF’s post 549,323.
-
WSCPD-CB
AskWoody Lounger -
WSCPD-CB
AskWoody LoungerDecember 17, 2006 at 11:34 am #1043841Hans,
FOr some reason the Macro’s dont work anymore. I am a bit confiused because I am sure they worked initially. When I first try to use the macro after logging on outlook asks if I want to ‘enable macros’ which I say ‘yes’. Even, the open categories dialogue box does not open anymore?? I have attached a couple of the macros which I am sure replicate those that you recommended. Any ideas on the problem? Thanks.
Sub SetCategoryIAC()
If Inspectors.Count > 0 Then
ActiveInspector.CurrentItem.Categories = “IAC”
End If
End SubSub ShowCategoriesDialog()
If Inspectors.Count Then
With ActiveInspector.CurrentItem
If .Class = olMail Then .ShowCategoriesDialog
End With
End If
End Sub -
WSHansV
AskWoody Lounger -
WSCPD-CB
AskWoody LoungerDecember 17, 2006 at 12:02 pm #1043843Hans – the advice that I have to have the email ‘open’ was the trick – thankyou. Do you know if there is a way to assign categories without having the mail item actually open, ie assigning a category when you have the mail item highlighted and are reading it in the preview pane?
Once again thanks for the fast response.
-
WSHansV
AskWoody Lounger -
WSJohnBF
AskWoody LoungerDecember 18, 2006 at 3:55 pm #1043898(Edited by JohnBF on 18-Dec-06 09:55. Code corrections)
If you want the flexibility of all selected items in the explorer pane, or the current open item, add this function to your code (I use it for all kinds of little macro thingies in Outlook):
Public Function GetSelectedItems() As Collection
Dim lngC As Long
Set GetSelectedItems = New Collection
If TypeName(Outlook.ActiveWindow) = “Explorer” Then
For lngC = 1 To ActiveExplorer.Selection.Count
GetSelectedItems.Add Outlook.ActiveExplorer.Selection(lngC)
Next lngC
Else
GetSelectedItems.Add Outlook.ActiveInspector.CurrentItem
End If
End FunctionThen modify Hans
-
WSCPD-CB
AskWoody LoungerDecember 18, 2006 at 12:02 pm #1043941Edited by HansV to crop huge screenshot to show only the relevant part
Thanks John, the code sound intriguing (for someone who likes tools but does not understand VBA!). I tried to establish a test case but came up with an error (refer to attached).
Can you please give me any hints on how I may have incorporated it incorrectly. Thanks
-
WSHansV
AskWoody Lounger -
WSJohnBF
AskWoody Lounger -
WSrory
AskWoody LoungerDecember 18, 2006 at 12:06 pm #1043945Hi Claude,
Try this amendment:Sub SetCategory() Dim collSelItems As Collection Dim lngC As Long Set collSelItems = GetSelectedItems If Not collSelItems Is Nothing Then For lngC = 1 To collSelItems.Count collSelItems(lngC).Categories = "MyCategory" Next lngC End If Set collSelItems = Nothing End Sub
HTH
-
WSCPD-CB
AskWoody LoungerDecember 18, 2006 at 12:26 pm #1043946Thanks all for helping me out. The code now works, however I am a little confused what the code adds. I tried selecting multiple items in the explorer pane to see if set categories to multiple items (ie what I understood from John’s “…of all selected items in explorer pane..”) but it still only adjusted one email item. To my understanding, this is the same function as the previous code.
I am interested to understand what the code does/add when you have time, and helped out a few other people with potentially higher priority problems…..
Thanks again.
-
WSrory
AskWoody Lounger -
WSJohnBF
AskWoody Lounger
-
-
-
-
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
CISA warns of hackers targeting critical oil infrastructure
by
Nibbled To Death By Ducks
2 hours, 27 minutes ago -
AI slop
by
Susan Bradley
1 hour, 37 minutes ago -
Chrome : Using AI with Enhanced Protection mode
by
Alex5723
3 hours, 43 minutes ago -
Two blank icons
by
CR2
10 hours, 13 minutes ago -
Documents, Pictures, Desktop on OneDrive in Windows 11
by
ThePhoenix
12 hours, 37 minutes ago -
End of 10
by
Alex5723
15 hours, 18 minutes ago -
End Of 10 : Move to Linux
by
Alex5723
15 hours, 47 minutes ago -
Single account cannot access printer’s automatic duplex functionality
by
Bruce
12 hours, 16 minutes ago -
test post
by
gtd12345
21 hours, 19 minutes ago -
Privacy and the Real ID
by
Susan Bradley
11 hours, 26 minutes ago -
MS-DEFCON 2: Deferring that upgrade
by
Susan Bradley
3 hours, 32 minutes ago -
Cant log on to oldergeeks.Com
by
WSJonharnew
1 day, 1 hour ago -
Upgrading from Win 10
by
WSjcgc50
3 hours, 2 minutes ago -
USB webcam / microphone missing after KB5050009 update
by
WSlloydkuhnle
20 hours, 46 minutes ago -
TeleMessage, a modified Signal clone used by US government has been hacked
by
Alex5723
1 day, 17 hours ago -
The story of Windows Longhorn
by
Cybertooth
1 day, 5 hours ago -
Red x next to folder on OneDrive iPadOS
by
dmt_3904
1 day, 19 hours ago -
Are manuals extinct?
by
Susan Bradley
6 hours, 46 minutes ago -
Canonical ditching Sudo for Rust Sudo -rs starting with Ubuntu
by
Alex5723
2 days, 4 hours ago -
Network Issue
by
Casey H
1 day, 15 hours ago -
Fedora Linux is now an official WSL distro
by
Alex5723
2 days, 16 hours ago -
May 2025 Office non-Security updates
by
PKCano
2 days, 16 hours ago -
Windows 10 filehistory including onedrive folder
by
Steve Bondy
2 days, 18 hours ago -
pages print on restart (Win 11 23H2)
by
cyraxote
1 day, 19 hours ago -
Windows 11 Insider Preview build 26200.5581 released to DEV
by
joep517
2 days, 20 hours ago -
Windows 11 Insider Preview build 26120.3950 (24H2) released to BETA
by
joep517
2 days, 21 hours ago -
Proton to drop prices after ruling against “Apple tax”
by
Cybertooth
3 days, 4 hours ago -
24H2 Installer – don’t see Option for non destructive install
by
JP
1 day, 20 hours ago -
Asking Again here (New User and Fast change only backups)
by
thymej
3 days, 15 hours ago -
How much I spent on the Mac mini
by
Will Fastie
23 hours, 7 minutes ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.