copying a custom view from a public folder and distributing programatically

Not open for further replies.


I am probably making this way more complicated than it needs to be. I know little about vba.

I am trying to piece together snippets of code to get the result. In a nutshell, I have created a custom view and assigned it to a particular public folder.

I want to be able to create a macro that a user can run, to copy that view in the public folder into their outlook and let the view be used for all mail folders.

The name of the Public Folder is "Public Folders\All Public Folders\VorysViews"

The ViewDriver sub and CreateView Function work if I use the original

Set objViews = objName.GetDefaultFolder(FolderType:=cnstFolderName).Views

but not with what I have been trying

Set objViews = GetFolder("Public Folders\All Public Folders\VorysViews").


I have been unsuccessful getting objViews to be the views in "Public Folders\All Public Folders\VorysViews"

The other Function "GetFolder" is where I went off on a tangent because I don't think I need to return just the final folder name. I just need to copy the views from "Public Folders\All Public Folders\VorysViews" and then save the view for all mail and post folders.

I'm sure I'm overlooking the obvious. Leading me in the right direction would be really helpful.

I bought "Microsoft Outlook Programming" but don't have the 2007 version yet.

Sub ViewDriver() 
'Calls the CreateView function to return a view. 
Dim objView As View 
Set objView = CreateView(strName:="Main Inbox Table_bymacro", cnstFolderName:=olFolderInbox, cnstViewType:=olTableView) 
'MsgBox "cnstFolderName is " & cnstFolderName 

If objView Is Nothing Then 
MsgBox "The view was not created." 
'MsgBox "The view: " & objFolder.Name & " is failing badly." 
'MsgBox "objview is " & objView.Name 
MsgBox "The view: " & objView.Name & " was created sucessfully." 
End If 
End Sub 
Function CreateView(ByVal strName As String, ByVal cnstFolderName As OlDefaultFolders, ByVal cnstViewType As OlViewType) As View 
'If succesful, returns a new view. 
Dim olApp As Outlook.Application 
Dim objName As NameSpace 
Dim objViews As Views 
MsgBox "cnstFolderName is " & cnstFolderName 
On Error Resume Next 
Set olApp = Outlook.Application 
Set objName = olApp.GetNamespace(Type:="MAPI") 
'Set objViews = objName.GetDefaultFolder(FolderType:=cnstFolderName).Views 
Set objViews = GetFolder("Public Folders\All Public Folders\VorysViews").Views 
'Set objFolder =  GetFolder("Public Folders\All Public Folders\Company\Sales") 
'Create the new view. 
Set CreateView = objViews.Add(Name:=strName, ViewType:=cnstViewType, 
End Function 
'The above SaveOption will save the view to all folders of this type 
Public Function GetFolder(strFolderPath As String) As MAPIFolder 
' strFolderPath needs to be something like 
'   "Public Folders\All Public Folders\Company\Sales" or 
'   "Personal Folders\Inbox\My Folder" 
Dim objApp As Outlook.Application 
Dim objNS As Outlook.NameSpace 
Dim colFolders As Outlook.Folders 
Dim objFolder As Outlook.MAPIFolder 
Dim arrFolders() As String 
Dim I As Long 
On Error Resume Next 
strFolderPath = Replace(strFolderPath, "/", "\") 
arrFolders() = Split(strFolderPath, "\") 
Set objApp = Application 
Set objNS = objApp.GetNamespace("MAPI") 
Set objFolder = objNS.Folders.Item(arrFolders(0)) 
If Not objFolder Is Nothing Then 
For I = 1 To UBound(arrFolders) 
Set colFolders = objFolder.Folders 
Set objFolder = Nothing 
Set objFolder = colFolders.Item(arrFolders(I)) 

If objFolder Is Nothing Then 
Exit For 

End If 
End If 
Set GetFolder = objFolder 
MsgBox "GetFolder is " & objFolder.Name 
MsgBox "objFolder is " & GetFolder.Name 
Set colFolders = Nothing 
Set objNS = Nothing 
Set objApp = Nothing 
End Function
Last edited by a moderator:

Ken Slovak - [MVP - Outlook]

Are we to assume you are using Outlook 2003 at the moment?

Dim pub As Outlook.MAPIFolder

Set pub =


Get the view from this:

Set oView = pub.Views.Item("whateverTheViewNameIs")

Before saving the view at the target folder set the SaveOption property to

Last edited by a moderator:


Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Hi I look for the same possibility in OL 2010
Not open for further replies.