Thread: Set Custom View
View Single Post
  #5  
Old April 2nd 09, 02:34 AM posted to microsoft.public.outlook.program_vba
Rafael[_2_]
external usenet poster
 
Posts: 28
Default 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
Ads