[mso] Re: another Outlook question re CATEGORIES

Here is an Outlook macro I wrote in reply to a similar question in May 2006. I 
believe it creates a new Outlook email, then prompts you to select a category 
(or maybe more than one). Then it goes through all your contacts. Every one 
that has the selected category is included on the email's BCC.
 
Option Explicit
 
Sub EmailFromCatg()
    Dim myOlApp As Outlook.Application
    Dim myMailItem As Outlook.MailItem
    Dim myNamespace As Outlook.NameSpace
    Dim myContacts As Outlook.Items
    Dim myItem As Outlook.ContactItem
    Dim myRecipient
    Dim SelCatg As String
'Creates an instance of the application
    Set myOlApp = Outlook.Application
'Creates email item
    Set myMailItem = myOlApp.CreateItem(olMailItem)
    myMailItem.Body = "Your Ad Here"
    myMailItem.Recipients.Add ("Jack Sprat") 'Replace with your name
    myMailItem.Subject = "TBD"
'Display the Show Categories dialog box
    myMailItem.ShowCategoriesDialog
    SelCatg$ = myMailItem.Categories
'Display the email
    myMailItem.Display
'Go through all my contacts. If any have the categories I just selected,
'add that person to the BCC recipient list.
    Set myNamespace = myOlApp.GetNamespace("MAPI")
    Set myContacts = myNamespace.GetDefaultFolder(olFolderContacts).Items
    For Each myItem In myContacts
        If (myItem.Class = olContact) Then
            If CompareCatg(SelCatg$, myItem.Categories) = True Then
                Set myRecipient = 
myMailItem.Recipients.Add(myItem.Email1Address)
                myRecipient.Type = olBCC
            End If
        End If
    Next
End Sub
 
Function CompareCatg(Catg1 As String, Catg2 As String) As Boolean
'Looks for a common category in two Outlook objects, each of which could
'have multiple categories assigned to it.
    Dim CatgToTest As String, CurrPos As Long, NewPos As Long
    CurrPos& = 0
'Find each category in Catg1 and search for it in Catg2
    Do While CurrPos& < Len(Catg1$)
        NewPos& = InStr(CurrPos& + 1, Catg1$, ",")
        If NewPos& > 0 Then
            CatgToTest$ = Mid(Catg1$, CurrPos& + 1, (NewPos& - 1) - CurrPos&)
            CurrPos& = NewPos&
        Else
            CatgToTest$ = Mid(Catg1$, CurrPos& + 1, Len(Catg1$) - CurrPos&)
            CurrPos& = Len(Catg1$)
        End If
'If the category from Catg1 (CatgToTest) is in Catg2, return TRUE & exit.
        If InStr(Catg2$, CatgToTest$) > 0 Then
            CompareCatg = True
            Exit Function
        End If
    Loop
'Didn't find any matching category. Return FALSE.
    CompareCatg = False
End Function
 
Hope this helps,
 
Hutch
--- On Tue, 10/21/08, James S. Huggins (mso) <MicrosoftOffice@xxxxxxxxx> wrote:

From: James S. Huggins (mso) <MicrosoftOffice@xxxxxxxxx>
Subject: [mso] another Outlook question re CATEGORIES
To: mso@xxxxxxxxxxxxx
Date: Tuesday, October 21, 2008, 11:27 PM

I abandoned my attempt to get Outlook to send the email I wanted and
resorted to using a different tool that I was able to implement MUCH faster
(http://JSH.us/gammadyne).

That said, I haven't given up yet.

My next task relates to categories.

I can go to the Contact window. I can select "by category" and see
all my
contacts grouped by category. Now I have a category called "family".
How do
I send an email to everyone in that category?

        
       
James S. Huggins
  
        writing you from Dallas, recovering from (1) my recent stroke, 
        (2) from rolling my car on Interstate 45 south of Huntsville, Texas
        but mostly (3) from the loss of Spot, my pet cat of 10 years .... 
        ... http://JSH.us/spot

...

*************************************************************
You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or
MicrosoftOffice@xxxxxxxxxxxxxxxx

To send mail to the group, simply address it to mso@xxxxxxxxxxxxx

To Unsubscribe from this group, visit the group's homepage and use the
dropdown menu at the top.  This will allow you to unsubscribe your email address
or change your email settings to digest or vacation (no mail).
http://www.freelists.org/webpage/mso

To be able to share files with the group, you must join our Yahoo sister group.
 This group will not allow for posting of emails, but will allow you to join and
share problem files, templates, etc.: 
http://tech.groups.yahoo.com/group/MicrosoftOffice . This group is for FILE
SHARING ONLY.

If you are using Outlook and you see a lot of unnecessary code in your email
messages, read these instructions that explain why and how to fix it:
http://personal-computer-tutor.com/abc3/v28/greg28.htm
*************************************************************



      
*************************************************************
You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or 
MicrosoftOffice@xxxxxxxxxxxxxxxx

To send mail to the group, simply address it to mso@xxxxxxxxxxxxx

To Unsubscribe from this group, visit the group's homepage and use the dropdown 
menu at the top.  This will allow you to unsubscribe your email address or 
change your email settings to digest or vacation (no mail).
http://www.freelists.org/webpage/mso

To be able to share files with the group, you must join our Yahoo sister group. 
 This group will not allow for posting of emails, but will allow you to join 
and share problem files, templates, etc.:  
http://tech.groups.yahoo.com/group/MicrosoftOffice . This group is for FILE 
SHARING ONLY.

If you are using Outlook and you see a lot of unnecessary code in your email 
messages, read these instructions that explain why and how to fix it:
http://personal-computer-tutor.com/abc3/v28/greg28.htm
*************************************************************

Other related posts: