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:
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:
Hi I look for the same possibility in OL 2010
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
B Copying data between atbs in a custom form Outlook VBA and Custom Forms 4
H Copying email address(es) in body of email and pasting in To field Outlook VBA and Custom Forms 1
P Copying ALL calendar entries from Calender in PST file to IMAP OST file? Using Outlook 1
R VBA for copying sent email to current folder under a shared mailbox Outlook VBA and Custom Forms 17
E Copying the whole e-mail body into excel Outlook VBA and Custom Forms 0
E Copying data from e-mail attachement to EXCEL file via macro Outlook VBA and Custom Forms 38
T Copying Outlook Account Setup For Desktop App Using Outlook 5
J Outlook - 2013 - Error msg when copying folders from Online Archives to another user's mailbox Using Outlook 0
Thiago Manzano Copying E-mails to a folder on HD Using Outlook 1
Diane Poremsky Mark Sent Items as Read After Copying with a Rule Using Outlook 0
crazyboy Copying BCM database from backed up mounted image to new drive BCM (Business Contact Manager) 2
oliv- Prevent copying shared contacts Outlook VBA and Custom Forms 5
Paul Butticaz Copying Contacts from SharePoint List (connected to Outlook) to another Conacts folder Using Outlook 1
K Outlook 2010 Not responding after IMAP folder deletion or copying. Using Outlook 2
Mary B Outlook 2013: Rule for copying new email to folder & marking that copy as read Using Outlook 1
S Calendar items are not being uploaded to after copying Using accounts in Outlook 1
P open reminders missing after copying outlook pst file Using Outlook 2
L Copying Emails using drag and drop Using Outlook 2
O New to Outlook 2013, dealing with copying vs. moving sent items Using Outlook 0
S Recover messages that disappeared when copying to folder Using Outlook 1
S Copying multiple messages to folders and keeping date/time detail Using Outlook 1
D Copying POP3 folders from Inbox to IMAP Inbox in Outlook 2003 Using Outlook 0
M Copying setups for mutiple users Using Outlook 2
T Location and simple copying of emails and settings, OL 2010 and Win 7 64bit. Using Outlook 3
A Copying additional contact fields when chosing "Contact from the same company" Using Outlook 5
A Copying cc email addresses to Excel - does not copy the <> Using Outlook 1
S Search Indexing (Copying Folders) Using Outlook 0
E Copying multiple folders to PST Outlook VBA and Custom Forms 2
N error when copying outlook data "can not copy: the path too deep" Using Outlook 6
N Copying outlook macros between pcs Outlook VBA and Custom Forms 1
R Copying Data from Exchange to PST file Outlook VBA and Custom Forms 1
V Copying contents from one field to another field Outlook VBA and Custom Forms 6
G Apply Custom Contacts form to all existing Contacts Outlook VBA and Custom Forms 1
G Add Map It button to Custom Contacts Form in Outlook Outlook VBA and Custom Forms 1
G Outlook 2021 Add Picture to Custom Contact Form Outlook VBA and Custom Forms 2
X Custom icon (not from Office 365) for a macro in Outlook Outlook VBA and Custom Forms 1
P Can't add custom field to custom Outlook form, it always adds to the Folder instead Outlook VBA and Custom Forms 2
AndyZ Contact Custom Form Tiny Text Outlook VBA and Custom Forms 3
A How to reduce size of custom contact form? Outlook VBA and Custom Forms 3
S Custom Contact card - need help creating one Outlook VBA and Custom Forms 1
S Outlook 2019 Custom outlook Add-in using Visual Studio Outlook VBA and Custom Forms 0
S Adding Custom Forms Outlook VBA and Custom Forms 4
Witzker How to get the button Karte ( map) in custom contact form Outlook VBA and Custom Forms 2
B Outlook 2019 Custom Email form - Edit default email form Outlook VBA and Custom Forms 6
D Outlook 365 Custom forms field limit? Outlook VBA and Custom Forms 4
J PSA: How to create custom keyboard shortcut for "Paste Unformatted Text" in Outlook on Windows Outlook VBA and Custom Forms 1
M copy field value to custom field Outlook VBA and Custom Forms 0
J Does the .fdm contain my custom form? How to make ol use it? - ol2007 Outlook VBA and Custom Forms 4
J ol2021 custom form not displaying pics Outlook VBA and Custom Forms 37
N "Perform a Custom Action" Outlook VBA and Custom Forms 0

Similar threads