ShowCategoriesDialog for multiple inbox items

Status
Not open for further replies.
P

PeterGates

I'm trying to set up a macro that opens the Categories dialog for items I

select from the Inbox (or other Outlook folder). Using the code below I can

assign categories for single mail items in turn (ie the dialog opens, I

select categories, they are applied to the first item and then the dialog

opens again for the next item).

Can anyone tell me a way to have the same cateories apply to the multiple

messages I select?

----
Sub ShowCategoriesDialog()

Dim OlExp As Outlook.Explorer

Dim OlSel As Outlook.Selection

Dim x As Integer

Set OlExp = Application.ActiveExplorer

Set OlSel = OlExp.Selection

For x = 1 To OlSel.Count

OlSel.item(x).ShowCategoriesDialog

Next x

End Sub

------
 
Just call to open that dialog once, on the first selected item. Then pull

the categories from the item after the dialog closes and apply those

categories to the remainder of the selection. If you want you can get the

existing categories before you call to open the dialog to be able to compare

and see which were added/removed.

"PeterGates" <PeterGates> wrote in message

news:D876CE7F-D3F8-484E-978D-35066D442F6E@microsoft.com...
> I'm trying to set up a macro that opens the Categories dialog for items I
> select from the Inbox (or other Outlook folder). Using the code below I
> can
> assign categories for single mail items in turn (ie the dialog opens, I
> select categories, they are applied to the first item and then the dialog
> opens again for the next item).

> Can anyone tell me a way to have the same cateories apply to the multiple
> messages I select?

> ----> Sub ShowCategoriesDialog()
> Dim OlExp As Outlook.Explorer
> Dim OlSel As Outlook.Selection
> Dim x As Integer

> Set OlExp = Application.ActiveExplorer
> Set OlSel = OlExp.Selection

> For x = 1 To OlSel.Count
> OlSel.item(x).ShowCategoriesDialog
> Next x
> End Sub
> ------
 
I'd move the ShowCategoriesDialog statement so that it runs before the For

> ... Next loop. Then use the loop to copy the Categories property value from

the first item to all the rest:

Set firstItem = OlSel.item(1)

firstItem.ShowCategoriesDialog

For x = 2 To OlSel.Count

OlSel.item(x).Categories = firstItem.Categories

Next x

"PeterGates" wrote:


> I'm trying to set up a macro that opens the Categories dialog for items I
> select from the Inbox (or other Outlook folder). Using the code below I can
> assign categories for single mail items in turn (ie the dialog opens, I
> select categories, they are applied to the first item and then the dialog
> opens again for the next item).

> Can anyone tell me a way to have the same cateories apply to the multiple
> messages I select?

> ----> Sub ShowCategoriesDialog()
> Dim OlExp As Outlook.Explorer
> Dim OlSel As Outlook.Selection
> Dim x As Integer

> Set OlExp = Application.ActiveExplorer
> Set OlSel = OlExp.Selection

> For x = 1 To OlSel.Count
> OlSel.item(x).ShowCategoriesDialog
> Next x
> End Sub
> ------
 
Thanks for your help, it was quite a simple solution when I think about it.

It hasn't solved my problem though...

Now when I run the macro I get a dialog for the first item and the newly

added categories are shown (as coloured boxes) in the inbox window against

this first selected mail item only. The others don't appear to pick up a

category.

I added some msgbox lines in to display the categories inside the For-Next

loop and they return that the category is being assigned.

Any idea why this is?

Updated code:

---
Sub ShowCategoriesDialog()

Dim OlExp As Outlook.Explorer

Dim OlSel As Outlook.Selection

Dim x As Integer

Set OlExp = Application.ActiveExplorer

Set OlSel = OlExp.Selection

Set FirstItem = OlSel.item(1)

FirstItem.ShowCategoriesDialog

MsgBox FirstItem.Categories, , "Item 1 Categories:"

For x = 2 To OlSel.Count

OlSel.item(x).Categories = FirstItem.Categories

MsgBox OlSel.item(x).Categories, , "Item " & x & " Categories:"

Next x

End Sub

---
"Sue Mosher [MVP]" wrote:


> I'd move the ShowCategoriesDialog statement so that it runs before the For
> ... Next loop. Then use the loop to copy the Categories property value from
> the first item to all the rest:

> Set firstItem = OlSel.item(1)
> firstItem.ShowCategoriesDialog
> For x = 2 To OlSel.Count
> OlSel.item(x).Categories = firstItem.Categories
> Next x

> "PeterGates" wrote:
>
> > I'm trying to set up a macro that opens the Categories dialog for items I
> > select from the Inbox (or other Outlook folder). Using the code below I can
> > assign categories for single mail items in turn (ie the dialog opens, I
> > select categories, they are applied to the first item and then the dialog
> > opens again for the next item).
> > Can anyone tell me a way to have the same cateories apply to the multiple
> > messages I select?
> > ----> > Sub ShowCategoriesDialog()
> > Dim OlExp As Outlook.Explorer
> > Dim OlSel As Outlook.Selection
> > Dim x As Integer
> > Set OlExp = Application.ActiveExplorer
> > Set OlSel = OlExp.Selection
> > For x = 1 To OlSel.Count
> > OlSel.item(x).ShowCategoriesDialog
> > Next x
> > End Sub
> > ------
 
I don't see any OlSel.item(x).Save statement, but that's partially my fault.

I left that out of my loop. Sorry.

Sue Mosher

"PeterGates" <PeterGates> wrote in message

news:D4608C67-4C79-41C1-99C1-4B271C8A9943@microsoft.com...
> Thanks for your help, it was quite a simple solution when I think about
> it.
> It hasn't solved my problem though...

> Now when I run the macro I get a dialog for the first item and the newly
> added categories are shown (as coloured boxes) in the inbox window against
> this first selected mail item only. The others don't appear to pick up a
> category.

> I added some msgbox lines in to display the categories inside the For-Next
> loop and they return that the category is being assigned.

> Any idea why this is?
> Updated code:

> ---> Sub ShowCategoriesDialog()
> Dim OlExp As Outlook.Explorer
> Dim OlSel As Outlook.Selection
> Dim x As Integer

> Set OlExp = Application.ActiveExplorer
> Set OlSel = OlExp.Selection
> Set FirstItem = OlSel.item(1)

> FirstItem.ShowCategoriesDialog
> MsgBox FirstItem.Categories, , "Item 1 Categories:"

> For x = 2 To OlSel.Count
> OlSel.item(x).Categories = FirstItem.Categories
> MsgBox OlSel.item(x).Categories, , "Item " & x & " Categories:"
> Next x
> End Sub
> ---
> "Sue Mosher [MVP]" wrote:
>
> > I'd move the ShowCategoriesDialog statement so that it runs before the
> > For
> > ... Next loop. Then use the loop to copy the Categories property value
> > from
> > the first item to all the rest:
>

>> Set firstItem = OlSel.item(1)
> > firstItem.ShowCategoriesDialog
> > For x = 2 To OlSel.Count
> > OlSel.item(x).Categories = firstItem.Categories
> > Next x
>

>> "PeterGates" wrote:
> >
> > > I'm trying to set up a macro that opens the Categories dialog for items
> > > I
> > > select from the Inbox (or other Outlook folder). Using the code below I
> > > can
> > > assign categories for single mail items in turn (ie the dialog opens, I
> > > select categories, they are applied to the first item and then the
> > > dialog
> > > opens again for the next item).
> >> > Can anyone tell me a way to have the same cateories apply to the
> > > multiple
> > > messages I select?
> >> > ----> > > Sub ShowCategoriesDialog()
> > > Dim OlExp As Outlook.Explorer
> > > Dim OlSel As Outlook.Selection
> > > Dim x As Integer
> >> > Set OlExp = Application.ActiveExplorer
> > > Set OlSel = OlExp.Selection
> >> > For x = 1 To OlSel.Count
> > > OlSel.item(x).ShowCategoriesDialog
> > > Next x
> > > End Sub
> > > ------
 
Absolutely no apologies needed, you've helped an Outlook VBA novice out a

lot. I doubt this will be my last post - I have a few ideas I want to try and

implement...

Many thanks and best wishes.

Peter

"Sue Mosher [MVP]" wrote:


> I don't see any OlSel.item(x).Save statement, but that's partially my fault.
> I left that out of my loop. Sorry.

> > Sue Mosher
> > >

> "PeterGates" <PeterGates> wrote in message
> news:D4608C67-4C79-41C1-99C1-4B271C8A9943@microsoft.com...
> > Thanks for your help, it was quite a simple solution when I think about
> > it.
> > It hasn't solved my problem though...
> > Now when I run the macro I get a dialog for the first item and the newly
> > added categories are shown (as coloured boxes) in the inbox window against
> > this first selected mail item only. The others don't appear to pick up a
> > category.
> > I added some msgbox lines in to display the categories inside the For-Next
> > loop and they return that the category is being assigned.
> > Any idea why this is?
> > Updated code:
> > ---> > Sub ShowCategoriesDialog()
> > Dim OlExp As Outlook.Explorer
> > Dim OlSel As Outlook.Selection
> > Dim x As Integer
> > Set OlExp = Application.ActiveExplorer
> > Set OlSel = OlExp.Selection
> > Set FirstItem = OlSel.item(1)
> > FirstItem.ShowCategoriesDialog
> > MsgBox FirstItem.Categories, , "Item 1 Categories:"
> > For x = 2 To OlSel.Count
> > OlSel.item(x).Categories = FirstItem.Categories
> > MsgBox OlSel.item(x).Categories, , "Item " & x & " Categories:"
> > Next x
> > End Sub
> > ---> > "Sue Mosher [MVP]" wrote:
> >
> >> I'd move the ShowCategoriesDialog statement so that it runs before the
> >> For
> >> ... Next loop. Then use the loop to copy the Categories property value
> >> from
> >> the first item to all the rest:
> >
> >> Set firstItem = OlSel.item(1)
> >> firstItem.ShowCategoriesDialog
> >> For x = 2 To OlSel.Count
> >> OlSel.item(x).Categories = firstItem.Categories
> >> Next x
> >
> >> "PeterGates" wrote:
> >
> >> > I'm trying to set up a macro that opens the Categories dialog for items
> >> > I
> >> > select from the Inbox (or other Outlook folder). Using the code below I
> >> > can
> >> > assign categories for single mail items in turn (ie the dialog opens, I
> >> > select categories, they are applied to the first item and then the
> >> > dialog
> >> > opens again for the next item).
> >> >> > Can anyone tell me a way to have the same cateories apply to the
> >> > multiple
> >> > messages I select?
> >> >> > ----> >> > Sub ShowCategoriesDialog()
> >> > Dim OlExp As Outlook.Explorer
> >> > Dim OlSel As Outlook.Selection
> >> > Dim x As Integer
> >> >> > Set OlExp = Application.ActiveExplorer
> >> > Set OlSel = OlExp.Selection
> >> >> > For x = 1 To OlSel.Count
> >> > OlSel.item(x).ShowCategoriesDialog
> >> > Next x
> >> > End Sub
> >> > ------


>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
Jack Farnan ShowCategoriesDialog for a shared mailbox? Outlook VBA and Custom Forms 3
R Select Multiple Graphic Objects Using Outlook 0
Hornblower409 Automatically or Manually Backup Multiple Versions of VbaProject.OTM Outlook VBA and Custom Forms 1
B Modify VBA to create a RULE to block multiple messages Outlook VBA and Custom Forms 0
C Outlook 365 Multiple different Signatures on Shared Mailbox Using Outlook 0
R Advise on using multiple instances of network files based on customers Outlook VBA and Custom Forms 8
D multiple email accounts - why do I have to choose the "from" account address?? Using Outlook 2
J Outlook Rules VBA Run a Script - Multiple Rules Outlook VBA and Custom Forms 0
C How to search for items in Outbox with multiple accounts? Using Outlook 20
K How to share multiple calendar items Using Outlook 1
K Multiple copies of task being created Using Outlook 2
S Auto forward for multiple emails Outlook VBA and Custom Forms 0
K Multiple Rules on Single Email Using Outlook 2
Cathy Rhone gmail listed multiple times Using Outlook 3
H Synchronize contacts and calendars across multiple devices Using Outlook 0
V Outlook 2016 Multiple recurring tasks getting created Using Outlook 0
K can't get custom form to update multiple contacts using VBA Outlook VBA and Custom Forms 3
Globalforester ItemAdd Macro - multiple emails Outlook VBA and Custom Forms 3
J Multiple calendars Using Outlook 0
C Multiple emails Using Outlook 8
C Outlook with Office365 - search across account, by date rate, in multiple folders - how? Using Outlook 2
E Asking user to select multiple options in a list in an email Outlook VBA and Custom Forms 0
A Multiple signatures Using Outlook 2
O Outlook tasks - Add text column with multiple lines Using Outlook 3
R How to get the Items object of the default mailbox of a specific account in a multiple account Outlook? Outlook VBA and Custom Forms 0
I Saving attachments from multiple emails and updating file name Outlook VBA and Custom Forms 0
L Multiple Inboxes Using Outlook 3
RBLampert Accessing Outlook accounts from multiple computers Using Outlook 8
Martull Forced signature when multiple accounts exist Outlook VBA and Custom Forms 4
T Outlook 2010 Correct way to map multiple contact fields Using Outlook 4
Y Open and Save Hyperlink Files in multiple emails Outlook VBA and Custom Forms 9
O Multiple email accounts - hesitate to create a new profile Using Outlook 3
papa.deblanc Multiple Instances Using Outlook 6
V Multiple Calendars in Outlook To-Do Bar; Office 365 Using Outlook 3
A Add multiple servers "on behalf of" email to "safe senders" list. Using Outlook 1
M possible to search Outlook for multiple email addresses at once? Using Outlook 1
C Macro to add multiple recipients to message Outlook VBA and Custom Forms 3
D [TOOL] QuickModules to sort emails very quickly to multiple folders Outlook VBA and Custom Forms 1
A Multiple Outlook Invites Received by One Person Using Outlook 4
N Selecting multiple calendar items Using Outlook 4
F Sharepoint tasks from multiple accounts in To-Do List Using Outlook 8
N Multiple instances of Outlook on Start Menu Using Outlook 2
D Edit Subject (Multiple Accounts) Outlook VBA and Custom Forms 5
B VBA Macro for assigning multiple Categories to an email in my Inbox Outlook VBA and Custom Forms 1
L Need to import multiple Outlook files to Office 365 Account Using Outlook 4
B Deleting multiple accounts Using Outlook 1
M Dialog called up multiple times when saving emails from macro Outlook VBA and Custom Forms 2
M Multiple spurious empty folders appear in archive files Using Outlook 3
G Bcc help - Preventing multiple forwards from a bcc'd distribution group Using Outlook 1
J Outlook Rules - Changing auto-submit address in multiple rules, according to rule name Outlook VBA and Custom Forms 0

Similar threads

Back
Top