| Code level: beginner Code area: Basic Outlook Printer Friendly Version | ||
| Title: New and improved GetFolder() function | ||
| Description: This updated version of my GetFolder() function can handle public folder paths in multilanguage environments. It uses Namespace.GetDefaultFolder if the path string is for Public Folders\All Public Folders. | ||
| Date: 30-Mar-2005 15:43 | ||
| Code level: beginner | ||
| Code area: Basic Outlook | ||
| Posted by: Sue Mosher | ||
| Body: |
||
| All 5comments |
| Page [ 1 ] | ||
|
|
Helmut Obertanner
31-Mar-2005 05:18
Hello Sue, veto the GetDefaultFolder( olPublicFoldersAllPublicFolders ) function don't work when you are in OL2003 CacheMode and Offline. Personaly i loop over the Session Folders and see if the name is Public Folder..... It's slower, but it works. Greets, Helmut |
|
|
|
Sue Mosher
31-Mar-2005 13:22
True, true -- thanks! I actually wrote this for a script where the user would always be online when running it, for other reasons. |
|
|
|
Dave
15-Jul-2008 16:35
Thank you for your working function. The best I could find on MSDN was for Outlook 2007. After trying to fit that into Outlook 2003 to no avail, I found your code. Cut and pasted, and it works great. |
|
|
|
Emory Brown
28-Oct-2008 15:35
Here's how I get a specific folder by name. Note that the folder name you want has to be a unique name since you aren't providing the whole path. Private Sub TestGettingFolder() Dim folderResult As Folder Dim nameOfFolderToFind As String ' Just the name, not the path nameOfFolderToFind = "Day Of Year" ' My day of year calendar GetFolderRecursive nameOfFolderToFind, Application.Session.Folders, folderResult MsgBox folderResult.Name & vbCr & folderResult.Items.Count ' Result name should be "Day Of Year" End Sub '---------------------------------------------------------------------------------------- Public Function GetFolderRecursive(FolderNameToFind As String, FoldersStartingPoint As Folders, ByRef ReturnFolder As Folder) As Boolean Dim subFolder As Folder Dim foundFolder As Boolean Dim regex As RegExp Set regex = New RegExp regex.Pattern = FolderNameToFind For Each subFolder In FoldersStartingPoint If regex.test(subFolder.Name) Then foundFolder = True GetFolderRecursive = True Set ReturnFolder = subFolder Else If Not foundFolder Then foundFolder = GetFolderRecursive(FolderNameToFind, subFolder.Folders, ReturnFolder) If foundFolder Then GetFolderRecursive = True Exit For End If End If End If Next subFolder Set regex = Nothing Set subFolder = Nothing End Function |
|
|
|
theUtmost
10-Feb-2010 20:10
I am such a newbie that I can't figure out which are the parts of the code I need to modify here to get it to look at my folder of interest. Can someone show me which parts to modify? I'd like to look in "Mailbox - User Name\Archive\Junk\IDG\TopNews", AND to combine with the following (modified) to format newly arrived items to plain text: [/code] Option Explicit Private WithEvents olInboxItems As Items Private Sub Application_Startup() Dim objNS As NameSpace Set objNS = Application.Session ' instantiate objects declared WithEvents Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items Set objNS = Nothing End Sub Private Sub olInboxItems_ItemAdd(ByVal Item As Object) On Error Resume Next Item.BodyFormat = olFormatPlain Item.Save Set Item = Nothing End Sub [/endcode] So the end result I'm after is that newly arrived mail items into "Mailbox - User Name\Archive\Junk\IDG\TopNews" should be formatted to plain text. I've setup "Method1" from here: http://www.outlookcode.com/article.aspx?id=62 Which piggy backs onto my existing rule that moves mail into the folder in the first place - that's working but it takes a long time as it sets properties on EVERY item in the folder and there are quite a few. So I'd like to use "Method2" but don't know enough to be able to adapt it for my needs/folder. Any pointers gratefully received... cheers, theUtmost |
|
| Page [ 1 ] | ||
| Post your comment name email |
