Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Outlook and VBA (http://www.outlookbanter.com/outlook-vba/)
-   -   Set Custom View (http://www.outlookbanter.com/outlook-vba/86564-set-custom-view.html)

Jeremy February 18th 09 03:48 PM

Set Custom View
 
Hi,

I'm using Outlook 2007 and that version of VB.

I have an awful lot of folders and I wanted to set each to a particular
custom view. I have written the code below to go through each folder and set
the custom view. However, it does not do this. I think I may need to "save"
after Application.ActiveExplorer.CurrentView = "J VIEW" however, I do not
know how to do this and keep getting an object error. Could someone help.

(As you might realise I want to set the custom view for all folders. I have
not found a macro to do this. I have tried cleaning the custom views using
"outlook.exe /cleanviews" and then changing the "messages" the default view -
this does not work and in fact "outlook.exe /cleanviews" does not properly
reset the "messages" view - different folders have different views despite
being set to the "messages" view.)

My code (pieced together as I can't program):

Sub ProcessAllFolders()
ProcessSubFolder Application.ActiveExplorer.CurrentFolder
MsgBox "All Done!", vbInformation + vbOKOnly, "Process All Folders Macro"
End Sub

Sub ProcessSubFolder(olkFolder As Outlook.MAPIFolder)
Dim olkSubFolder As Outlook.MAPIFolder


'Replace the following line with the code you want to run for each folder
'Debug.Print olkFolder.FolderPath
Application.ActiveExplorer.CurrentView = "J VIEW"


For Each olkSubFolder In olkFolder.Folders
ProcessSubFolder olkSubFolder
Next
Set olkSubFolder = Nothing
End Sub




Ken Slovak - [MVP - Outlook] February 18th 09 08:04 PM

Set Custom View
 
You have to both Apply the setting and Save it.

Get Application.ActiveExplorer.CurrentView as a View object and then use the
View object Apply and then Save methods.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Jeremy" wrote in message
...
Hi,

I'm using Outlook 2007 and that version of VB.

I have an awful lot of folders and I wanted to set each to a particular
custom view. I have written the code below to go through each folder and
set
the custom view. However, it does not do this. I think I may need to
"save"
after Application.ActiveExplorer.CurrentView = "J VIEW" however, I do not
know how to do this and keep getting an object error. Could someone help.

(As you might realise I want to set the custom view for all folders. I
have
not found a macro to do this. I have tried cleaning the custom views using
"outlook.exe /cleanviews" and then changing the "messages" the default
view -
this does not work and in fact "outlook.exe /cleanviews" does not properly
reset the "messages" view - different folders have different views despite
being set to the "messages" view.)

My code (pieced together as I can't program):

Sub ProcessAllFolders()
ProcessSubFolder Application.ActiveExplorer.CurrentFolder
MsgBox "All Done!", vbInformation + vbOKOnly, "Process All Folders
Macro"
End Sub

Sub ProcessSubFolder(olkFolder As Outlook.MAPIFolder)
Dim olkSubFolder As Outlook.MAPIFolder


'Replace the following line with the code you want to run for each
folder
'Debug.Print olkFolder.FolderPath
Application.ActiveExplorer.CurrentView = "J VIEW"


For Each olkSubFolder In olkFolder.Folders
ProcessSubFolder olkSubFolder
Next
Set olkSubFolder = Nothing
End Sub





Jeremy February 19th 09 10:02 AM

Set Custom View
 
Hi.

I understand the principle but I can't code very well. Could you tell me
precisely the code?

If I could get the object I think I could code the apply and save method as
it's just object.apply & object.save (i think). Would you mind telling me the
line(s) of code that will give me / get me an object though, I tried:

Get Application.ActiveExplorer.CurrentView as a View object

and as I thought, that doesn't work!

Thanks - J



"Ken Slovak - [MVP - Outlook]" wrote:

You have to both Apply the setting and Save it.

Get Application.ActiveExplorer.CurrentView as a View object and then use the
View object Apply and then Save methods.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Jeremy" wrote in message
...
Hi,

I'm using Outlook 2007 and that version of VB.

I have an awful lot of folders and I wanted to set each to a particular
custom view. I have written the code below to go through each folder and
set
the custom view. However, it does not do this. I think I may need to
"save"
after Application.ActiveExplorer.CurrentView = "J VIEW" however, I do not
know how to do this and keep getting an object error. Could someone help.

(As you might realise I want to set the custom view for all folders. I
have
not found a macro to do this. I have tried cleaning the custom views using
"outlook.exe /cleanviews" and then changing the "messages" the default
view -
this does not work and in fact "outlook.exe /cleanviews" does not properly
reset the "messages" view - different folders have different views despite
being set to the "messages" view.)

My code (pieced together as I can't program):

Sub ProcessAllFolders()
ProcessSubFolder Application.ActiveExplorer.CurrentFolder
MsgBox "All Done!", vbInformation + vbOKOnly, "Process All Folders
Macro"
End Sub

Sub ProcessSubFolder(olkFolder As Outlook.MAPIFolder)
Dim olkSubFolder As Outlook.MAPIFolder


'Replace the following line with the code you want to run for each
folder
'Debug.Print olkFolder.FolderPath
Application.ActiveExplorer.CurrentView = "J VIEW"


For Each olkSubFolder In olkFolder.Folders
ProcessSubFolder olkSubFolder
Next
Set olkSubFolder = Nothing
End Sub






Ken Slovak - [MVP - Outlook] February 20th 09 04:32 PM

Set Custom View
 
Dim oView As Outlook.View

Set oView = Application.ActiveExplorer.CurrentView

' other code

oView.Apply
oView.Save

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Jeremy" wrote in message
...
Hi.

I understand the principle but I can't code very well. Could you tell me
precisely the code?

If I could get the object I think I could code the apply and save method
as
it's just object.apply & object.save (i think). Would you mind telling me
the
line(s) of code that will give me / get me an object though, I tried:

Get Application.ActiveExplorer.CurrentView as a View object

and as I thought, that doesn't work!

Thanks - J



Rafael[_2_] April 2nd 09 02:34 AM

Set Custom View
 
I tried all these methods without success and I decided to go the hard way
about it but it works just like I want it.

Here is what I did:

1. Configure the view they way I want it (fields, formating, etc.)
2. Run a script to extract the XML settings from the current view and save
it to a file
3. Use a form to list all current forms and add a new view of my own
4. If I select my custom view from the list, I update its XML property with
the xml settings from step 2, save it and then apply it to the current
explorer.
5. Done. I have my view with all the fields I need and if I need to modify
it, I can always update the text file containing my xml code.

Here is the code to extract the XML setting:

Dim myOLapp1 As Outlook.Application = Globals.ThisAddIn.Application
Dim myExpl As Outlook.Explorer = myOLapp1.ActiveExplorer
Dim myView1 As TableView = myExpl.CurrentView
Dim myfol As Outlook.MAPIFolder = myExpl.CurrentFolder
Dim myfields As ViewFields = myView1.ViewFields
'Dim myxmlItem As ViewField
Dim file As System.IO.StreamWriter
file =
My.Computer.FileSystem.OpenTextFileWriter("C:\View XMLSettings.txt", False)
If myfol.DefaultItemType = OlItemType.olContactItem Then
file.WriteLine(myView1.XML)
file.Close()
End If
myOLapp1 = Nothing
myExpl = Nothing
myfol = Nothing


All times are GMT +1. The time now is 07:04 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com