-
Feb 18th, 2021, 06:18 PM
#1
Thread Starter
Hyperactive Member
Getting the active mailbox
Hi,
I am trying to create a macro that assigns categories to a mail item. The problem is that I am working with several separate inboxes, each having their own category list. So before I assign anything I want to make sure that the category assigned actually exists in the mailbox in which I am working. Thusfar my code (below) is grabbing my (personal and primary) inbox only and ignoring the others. I would imagine the problem is somewhere with the namespace statement where instead of using the Application.GetNamespace("MAPI") I should be pointing to the active namespace, except I have no idea how to do that and Google hasn't been very forthcoming. Thanks in advance for your help.
Code:
Public Sub TestCategoryStuff()
Dim myNameSpace As NameSpace
Dim myCategory As Category
Dim strCatName As String
Dim strResult As String
Set myNameSpace = Application.GetNamespace("MAPI")
If myNameSpace.Categories.Count > 0 Then
' The following is just to generate a list of categories so I can see what's there.
' The final function will compare the desired category to the list and
' return True if there is a match and False if not.
For Each myCategory In myNameSpace.Categories
strCatName = myCategory.Name
strResult = strResult & "; " & strCatName
Next
End If
Set myCategory = Nothing
Set myNameSpace = Nothing
MsgBox strResult
End Sub
As I stand here, on the fringes of my understanding, and look out over the
vast void before me, I realize all that lies ahead: The rest of Dot.Net. . .
-
Feb 19th, 2021, 01:50 AM
#2
Re: Getting the active mailbox
Shouldn't you search for a Folder?
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Feb 19th, 2021, 05:13 PM
#3
Thread Starter
Hyperactive Member
Re: Getting the active mailbox
Hmm, could you be more specific? It would appear that categories are associated with mailboxes, since all of the folders within that mailbox reference the same list. However I could be wrong (It has happened before)
Thanks
As I stand here, on the fringes of my understanding, and look out over the
vast void before me, I realize all that lies ahead: The rest of Dot.Net. . .
-
Feb 20th, 2021, 02:50 AM
#4
Re: Getting the active mailbox
Sub SetCurrentFolder(strMailboxName As String)
Dim myNamespace As Outlook.NameSpace
Dim myFolder As Outlook.Folder
Set myNamespace = ThisOutlookSession.GetNamespace("MAPI")
Set myFolder = myNamespace.Folders(strMailboxName)
Set myFolder = myFolder.Folders("Inbox")
Set Application.ActiveExplorer.CurrentFolder = myFolder
ExitRoutine:
Set myNamespace = Nothing
Set myFolder = Nothing
End Sub
this code is copied from a recent thread, where the poster was accessing multiple inboxes, but all mailboxes are still within the same namespace, so i believe there would only be one collection of categories per outlook application
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|