![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
Hi,
I need to create a macro that will clear filters from the current view. I believe that this should be achieved by manipulating the xml. I started out with the following: Sub clearFiltersCurrentView() Dim strXML As String Dim intFilterStart As Integer Dim intFilterEnd As Integer strXML = Application.ActiveExplorer.CurrentView.XML intFilterStart = InStr(1, strXML, "filter", vbTextCompare) intFilterEnd = InStr(1, strXML, "/filter", vbTextCompare) Do While (intFilterStart 0 Or intFilterEnd 0) If (intFilterStart = 0 Or intFilterEnd = 0) Then MsgBox "error" strXML = Left(strXML, intFilterStart - 1) & Right(strXML, Len(strXML) - (intFilterEnd - 1) - Len("/filter")) intFilterStart = InStr(1, strXML, "filter", vbTextCompare) intFilterEnd = InStr(1, strXML, "/filter", vbTextCompare) Loop Application.ActiveExplorer.CurrentView.XML = strXML End Sub Unfortunately, even though my strXML appears valid XML it doesn't seem to remove the filter info from the XML of the current view. I have tried various other methods to no avail. A simple line such as: Application.ActiveExplorer.CurrentView.XML = replace(Application.ActiveExplorer.CurrentView.XML ,"UK","France") works perfectly in changing the filter keyword from UK to France. However I can't work out how to remove the filter altogether. I've also noticed that if I apply a filter to a view, remove it and then examine the output of Application.ActiveExplorer.CurrentView.XML the filter information is still there even though it is not active. It also tends to move to a different line in the XML (although my understanding is that this makes no difference). It's as if there's another variable in the XML that tells the view whether to apply the filter but I can't find it. Please help! |
Ads |
#3
|
|||
|
|||
![]()
Ken,
Thanks for confirming that removing the filter text is the correct way. I had removed the save/apply lines because I've found that they are not necessary when changing other aspects of the xml. I have now added them and my code still does not work. Code is as follows: Sub clearFiltersCurrentView() Dim strXML As String Dim intFilterStart As Integer Dim intFilterEnd As Integer Dim vCurrentView As View Set vCurrentView = Application.ActiveExplorer.CurrentView strXML = vCurrentView.XML intFilterStart = InStr(1, strXML, "filter", vbTextCompare) intFilterEnd = InStr(1, strXML, "/filter", vbTextCompare) Do While (intFilterStart 0 Or intFilterEnd 0) If (intFilterStart = 0 Or intFilterEnd = 0) Then MsgBox "error" strXML = Left(strXML, intFilterStart - 1) & Right(strXML, Len(strXML) - (intFilterEnd - 1) - Len("/filter")) intFilterStart = InStr(1, strXML, "filter", vbTextCompare) intFilterEnd = InStr(1, strXML, "/filter", vbTextCompare) Loop If InStr(1, strXML, "sortdesc/sort", vbTextCompare) Then strXML = Replace(strXML, "sortdesc/sort", "sortasc/sort") Else strXML = Replace(strXML, "sortasc/sort", "sortdesc/sort") End If Debug.Print strXML vCurrentView.XML = strXML vCurrentView.Save vCurrentView.Apply Debug.Print vCurrentView.XML End Sub I have added the step to toggle the sorting order to be sure that strXML is being applied and the column sorting in my outlook view is indeed inverting every time I run it. The Debug.Print strXML output verifies that there is no filter line in the new XML, however it persists in vCurrentView.XML even after the changes are being applied. It's as if VBA will only change the XML for XML tags that you offer a replacement for but won't delete them. So I'm still stuck! Chris "Ken Slovak - [MVP - Outlook]" wrote: Removing the filter /filter text will remove the filter. However, you are not saving the view and applying it after you change it. You need to do that to persist your changes and to make them permanent. After you set the new View.XML you should get the View object and use its Save(), then Apply() methods. In Outlook 2007 you could just get the View object and use the new Filter property set to null string before using Save() and Apply(). -- 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 "Chris Quayle" Chris wrote in message ... Hi, I need to create a macro that will clear filters from the current view. I believe that this should be achieved by manipulating the xml. I started out with the following: Sub clearFiltersCurrentView() Dim strXML As String Dim intFilterStart As Integer Dim intFilterEnd As Integer strXML = Application.ActiveExplorer.CurrentView.XML intFilterStart = InStr(1, strXML, "filter", vbTextCompare) intFilterEnd = InStr(1, strXML, "/filter", vbTextCompare) Do While (intFilterStart 0 Or intFilterEnd 0) If (intFilterStart = 0 Or intFilterEnd = 0) Then MsgBox "error" strXML = Left(strXML, intFilterStart - 1) & Right(strXML, Len(strXML) - (intFilterEnd - 1) - Len("/filter")) intFilterStart = InStr(1, strXML, "filter", vbTextCompare) intFilterEnd = InStr(1, strXML, "/filter", vbTextCompare) Loop Application.ActiveExplorer.CurrentView.XML = strXML End Sub Unfortunately, even though my strXML appears valid XML it doesn't seem to remove the filter info from the XML of the current view. I have tried various other methods to no avail. A simple line such as: Application.ActiveExplorer.CurrentView.XML = replace(Application.ActiveExplorer.CurrentView.XML ,"UK","France") works perfectly in changing the filter keyword from UK to France. However I can't work out how to remove the filter altogether. I've also noticed that if I apply a filter to a view, remove it and then examine the output of Application.ActiveExplorer.CurrentView.XML the filter information is still there even though it is not active. It also tends to move to a different line in the XML (although my understanding is that this makes no difference). It's as if there's another variable in the XML that tells the view whether to apply the filter but I can't find it. Please help! |
#4
|
|||
|
|||
![]()
This isn't Outlook 2007 is it?
I'm not sure this idea will work: Get the XML, Name, ViewType and SaveOption property values. Also capture the LockUserChanges value. Change the current view to another of the views available in the Views collection Then go up one level to the Views collection and delete that view. Add your view with all the properties you saved, using the Add() function. Then drop down to the View object you got from Add() and set the view and apply and save it. See if that does something for you. -- 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 "Chris Quayle" wrote in message ... Ken, Thanks for confirming that removing the filter text is the correct way. I had removed the save/apply lines because I've found that they are not necessary when changing other aspects of the xml. I have now added them and my code still does not work. Code is as follows: Sub clearFiltersCurrentView() Dim strXML As String Dim intFilterStart As Integer Dim intFilterEnd As Integer Dim vCurrentView As View Set vCurrentView = Application.ActiveExplorer.CurrentView strXML = vCurrentView.XML intFilterStart = InStr(1, strXML, "filter", vbTextCompare) intFilterEnd = InStr(1, strXML, "/filter", vbTextCompare) Do While (intFilterStart 0 Or intFilterEnd 0) If (intFilterStart = 0 Or intFilterEnd = 0) Then MsgBox "error" strXML = Left(strXML, intFilterStart - 1) & Right(strXML, Len(strXML) - (intFilterEnd - 1) - Len("/filter")) intFilterStart = InStr(1, strXML, "filter", vbTextCompare) intFilterEnd = InStr(1, strXML, "/filter", vbTextCompare) Loop If InStr(1, strXML, "sortdesc/sort", vbTextCompare) Then strXML = Replace(strXML, "sortdesc/sort", "sortasc/sort") Else strXML = Replace(strXML, "sortasc/sort", "sortdesc/sort") End If Debug.Print strXML vCurrentView.XML = strXML vCurrentView.Save vCurrentView.Apply Debug.Print vCurrentView.XML End Sub I have added the step to toggle the sorting order to be sure that strXML is being applied and the column sorting in my outlook view is indeed inverting every time I run it. The Debug.Print strXML output verifies that there is no filter line in the new XML, however it persists in vCurrentView.XML even after the changes are being applied. It's as if VBA will only change the XML for XML tags that you offer a replacement for but won't delete them. So I'm still stuck! Chris |
#5
|
|||
|
|||
![]()
Thanks for your help. In the end I created a new view called 'Unfiltered
view' and applied strXML (with fliter text removed) to that view and loaded it each time I want to clear fliters. Then I use a separate view 'Filtered view' to be loaded every time I want to apply a filter and use macros to make sure a filter never gets applied to Unfiltered. "Ken Slovak - [MVP - Outlook]" wrote: This isn't Outlook 2007 is it? I'm not sure this idea will work: Get the XML, Name, ViewType and SaveOption property values. Also capture the LockUserChanges value. Change the current view to another of the views available in the Views collection Then go up one level to the Views collection and delete that view. Add your view with all the properties you saved, using the Add() function. Then drop down to the View object you got from Add() and set the view and apply and save it. See if that does something for you. -- 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 "Chris Quayle" wrote in message ... Ken, Thanks for confirming that removing the filter text is the correct way. I had removed the save/apply lines because I've found that they are not necessary when changing other aspects of the xml. I have now added them and my code still does not work. Code is as follows: Sub clearFiltersCurrentView() Dim strXML As String Dim intFilterStart As Integer Dim intFilterEnd As Integer Dim vCurrentView As View Set vCurrentView = Application.ActiveExplorer.CurrentView strXML = vCurrentView.XML intFilterStart = InStr(1, strXML, "filter", vbTextCompare) intFilterEnd = InStr(1, strXML, "/filter", vbTextCompare) Do While (intFilterStart 0 Or intFilterEnd 0) If (intFilterStart = 0 Or intFilterEnd = 0) Then MsgBox "error" strXML = Left(strXML, intFilterStart - 1) & Right(strXML, Len(strXML) - (intFilterEnd - 1) - Len("/filter")) intFilterStart = InStr(1, strXML, "filter", vbTextCompare) intFilterEnd = InStr(1, strXML, "/filter", vbTextCompare) Loop If InStr(1, strXML, "sortdesc/sort", vbTextCompare) Then strXML = Replace(strXML, "sortdesc/sort", "sortasc/sort") Else strXML = Replace(strXML, "sortasc/sort", "sortdesc/sort") End If Debug.Print strXML vCurrentView.XML = strXML vCurrentView.Save vCurrentView.Apply Debug.Print vCurrentView.XML End Sub I have added the step to toggle the sorting order to be sure that strXML is being applied and the column sorting in my outlook view is indeed inverting every time I run it. The Debug.Print strXML output verifies that there is no filter line in the new XML, however it persists in vCurrentView.XML even after the changes are being applied. It's as if VBA will only change the XML for XML tags that you offer a replacement for but won't delete them. So I'm still stuck! Chris |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
OUTLOOK 2003 - CALENDAR - COPYING appointments in Current View ACT | Aloha | Outlook - Calandaring | 1 | May 6th 08 08:36 AM |
Programmatically setting a filter on a day/week/month view in Outlook 2003 | sn | Add-ins for Outlook | 1 | May 7th 07 02:36 PM |
Outlook 2003 cannot remove Inbox filter | Beemer | Outlook - General Queries | 1 | January 25th 07 03:29 PM |
"There are no items to show in this view" in Taskpad. No filter. Cant reset Current view | [email protected] | Outlook - Calandaring | 0 | February 3rd 06 06:36 PM |
current & future calendar on monthly view outlook 2003 | camsnanny | Outlook - Calandaring | 1 | January 27th 06 10:28 PM |