Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook View (Field Chooser) Automation

Status
Not open for further replies.

djtech2k

MIS
Jul 24, 2003
1,097
US
I have a simple, but tricky request laid on me. I need to be able to automate a change to the "columns" shown in outlook, specifically on the search results screen.

You can do this manually by right-clicking the column header and selecting field chooser. I need to do this on a wide scale with something like gpo, prf, script, etc.

Any ideas? I have looked everywhere and cannot find out where this is stored in outlook. This is specific for outlook 2003.

I am stuck trying to find this change.
 
Use the macro recorder. Start a new macro recording in Outlook. Manually make your changes. Stop the recorder. Use the VBA editor to see the code used to make your changes.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Mark, how do you start a new macro recording in ol2003 ?
 
I will have to look into that but I need a way to do this without user intervention and make it a standard across an enterprise.

I have a requirement to get this set in an "automatic" fashion, like via gpo, script, etc. I also may have the option to customize the profile prf, but I still cnanot find out where this thing is stored.
 
PHV, I stand corrected. I didn't realize there wasn't a record option in Outlook. Nothing like having inconsistency in the Office products!

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
So it looks like this info may be stored in the Exchange mailbox or PST in the views/forms.

Now I just ened to leverage it to change it. The only code I can find is something to run as an HTA, but its view only. I will post it here so maybe you guys will have an idea how I can leverage it to actually make the changes I want.

Thanks guys.

Code:
<script language=vbscript for=ViewCtlFolder event=Activate()>
	Call ViewCtlFolder_Activate()
</script>
<script language=vbscript for=ViewCtlFolder event=BeforeViewSwitch()>
	Call ViewCtlFolder_BeforeViewSwitch(newView, Cancel)
</script>
<script language=vbscript for=ViewCtlFolder event=SelectionChange()>
    Call ViewCtlFolder_SelectionChange()
</script>
<script language=vbscript for=ViewCtlFolder event=ViewSwitch()>
	Call ViewCtlFolder_ViewSwitch()
</script>
<script language=vbscript>
    Sub ViewCtlFolder_Activate()
		MsgBox "Activate Event Fired"
    End Sub
    Sub ViewCtlFolder_BeforeViewSwitchEvent(newView, Cancel)
		MsgBox "Before View Switch Event Fired"
    End Sub
    Sub ViewCtlFolder_SelectionChange()
		MsgBox "Selection Change Event Fired"
    End Sub
    Sub ViewCtlFolder_ViewSwitch()
		MsgBox "View Switch Event Fired"
    End Sub
</script>
</head>
<body>

<p>
<object classid="clsid:0006F063-0000-0000-C000-000000000046" width=600 height=400 id="ViewCtlFolder" data="DATA:application/x-oleobject;BASE64,Y/AGAAAAAADAAAAAAAAARgACAADYEwAA2BMAAAgAAAAAAAgAAAAAAAgACgAAAE0AQQBQAEkAAAAJAAAAAAAAAAAAAAAAAAAAAAAJAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAALAAAA" VIEWASTEXT>
</object>
</p>

</body>
</html>
 
NEW Info:

I have the following code that appears to address the views, but outlook does nto show the change. The code appears to "add" the column to the view, but outlook does not show it.

FYI, when I look in outlook 2007, it shows my current view is Messages. I am testing this version on 2007, but again, I need it for both if possible.

I think this may be closer, but some of you code guru's may be able to put me over the top.


Code:
Const olFolderInbox = 6
Set olApp = CreateObject("Outlook.Application")
Set objName = olApp.GetNameSpace("MAPI")
Set objViews = objName.GetDefaultFolder(olFolderInbox).Views


Set oTableView = objViews.Item("Table View")
Set oViewFields = objViews.Item("View Fields")
Set oViewField = objViews.Item("View Field")
Set oInbox = objName.GetDefaultFolder(olFolderInbox)

wscript.echo oInbox.CurrentView & ":" & oInbox.CurrentView.ViewType' & ":" & oInbox.CurrentView.Fields
Set myView = oInbox.CurrentView
Set oViewField = oInbox.CurrentView.ViewFields.Insert("Sent")
 
So I now have some working code, BUT I still need some help.

I am able to get the value set in 2003 and 2007, BUT only on the INBOX view. I NEED to have it work on the "Advanced Find" screen. So when you do an advanced search it opens the new screen. I need to change the columns there. This info seems to be stored in the mailbox, so I need to find where to make this column change happen on that "Advanced Find" screen.

I am not opposed to using compiled VB.net and/or an outlook add-in via VBA, but dont know where to start on that one.

So to do this on the regular "Inbox" view, it is different for 2003 vs 2007. I will post what I have that works on both.

Outlook 2007:
Code:
Const olFolderInbox = 6
Set olApp = CreateObject("Outlook.Application")
Set objName = olApp.GetNameSpace("MAPI")
Set objViews = objName.GetDefaultFolder(olFolderInbox).Views


Set oTableView = objViews.Item("Table View")
Set oViewFields = objViews.Item("View Fields")
Set oViewField = objViews.Item("View Field")
Set oInbox = objName.GetDefaultFolder(olFolderInbox)


wscript.echo oInbox.CurrentView & ":" & oInbox.CurrentView.ViewType' & ":" & oInbox.CurrentView.Fields
Set myView = oInbox.CurrentView
Set oViewField = oInbox.CurrentView.ViewFields.Add("Sent")
myView.Save()
myView.Apply()

Outlook 2003
Code:
Const ForReading = 1
Const olFolderInbox = 6
Set olApp = CreateObject("Outlook.Application")
Set objName = olApp.GetNameSpace("MAPI")
Set objViews = objName.GetDefaultFolder(olFolderInbox).Views


Set oTableView = objViews.Item("Table View")
Set oViewFields = objViews.Item("View Fields")
Set oViewField = objViews.Item("View Field")
Set oInbox = objName.GetDefaultFolder(olFolderInbox)

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("output-file.xml",ForReading)
strXML = objTextFile.ReadAll
objTextFile.Close

oInbox.CurrentView.XML = strXML
oInbox.CurrentView.Save()
oInbox.CurrentView.Apply()

Any help is appreciated.
 
Any ideas? I dont care if its vbscript, VB.NET, outlook plug-in, etc. I just need to get this resolved.

Any ideas?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top