I am developing a mail macro that a number of users will run in Outlook. Currently I use the following approach to search my Inbox...
Set objNamespace = Application.GetNamespace("MAPI")
'Replace line below with code that sets olShareName equal to the current 'outlook user's primary e-mail account.
Set olShareName = objNamespace.CreateRecipient("rpullman@dogs.com")
Set objFolder = objNamespace.GetSharedDefaultFolder(olShareName, olFolderInbox)
Set DestFolder = objNamespace.GetSharedDefaultFolder(olShareName, olFolderToDo)
strFilter = "@SQL=" & Chr(34) & "urn:schemas:httpmail:subject" & Chr(34) & " like '%Dogs Secretly Control the World%'"
Set filteredItems = objFolder.Items.Restrict(strFilter)
I want to make this code portable in the sense that the olShareName
variable will be set to whomever is running the macro's primary e-mail address.
If, for instance, my colleagues were to use this macro, and they had the following e-mail addresses (that are accessed through outlook): bailey@dogs.com and molly@dogs.com, they should be able to run it without having to key in any modification to the code.
Obviously, I could use an input-box and have them type in their e-mail address, but I want to avoid that.