Help!

Remove filter from current view - outlook 2003

 
  

Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> Programming VBA RSS
Next:  Update all labels problem with Word 2007 + Vista  
Author Message
Chris Quayle
External


Since: Mar 27, 2009
Posts: 1



PostPosted: Fri Mar 27, 2009 5:59 am    Post subject: Remove filter from current view - outlook 2003
Archived from groups: microsoft>public>outlook>program_vba (more info?)

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!
Back to top
Ken Slovak - [MVP - Outlo
External


Since: Oct 17, 2003
Posts: 3355



PostPosted: Fri Mar 27, 2009 10:52 am    Post subject: Re: Remove filter from current view - outlook 2003 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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 Quayle.TakeThisOut@discussions.microsoft.com> wrote in message
news:2BAC4B02-2918-47EB-883B-8F9296051334@microsoft.com...
> 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!
Back to top
Chris Quayle
External


Since: Mar 27, 2009
Posts: 2



PostPosted: Fri Mar 27, 2009 10:52 am    Post subject: Re: Remove filter from current view - outlook 2003 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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, "<sort>desc</sort>", vbTextCompare) Then
strXML = Replace(strXML, "<sort>desc</sort>", "<sort>asc</sort>")
Else
strXML = Replace(strXML, "<sort>asc</sort>", "<sort>desc</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 Quayle DeleteThis @discussions.microsoft.com> wrote in message
> news:2BAC4B02-2918-47EB-883B-8F9296051334@microsoft.com...
> > 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!
>
>
Back to top
Ken Slovak - [MVP - Outlo
External


Since: Oct 17, 2003
Posts: 3355



PostPosted: Fri Mar 27, 2009 4:39 pm    Post subject: Re: Remove filter from current view - outlook 2003 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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" <ChrisQuayle DeleteThis @discussions.microsoft.com> wrote in message
news:F7854F5D-67F5-47B4-B1FD-BB786B28E5F5@microsoft.com...
> 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, "<sort>desc</sort>", vbTextCompare) Then
> strXML = Replace(strXML, "<sort>desc</sort>", "<sort>asc</sort>")
> Else
> strXML = Replace(strXML, "<sort>asc</sort>", "<sort>desc</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
Back to top
Chris Quayle
External


Since: Mar 27, 2009
Posts: 2



PostPosted: Mon Mar 30, 2009 7:16 am    Post subject: Re: Remove filter from current view - outlook 2003 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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" <ChrisQuayle RemoveThis @discussions.microsoft.com> wrote in message
> news:F7854F5D-67F5-47B4-B1FD-BB786B28E5F5@microsoft.com...
> > 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, "<sort>desc</sort>", vbTextCompare) Then
> > strXML = Replace(strXML, "<sort>desc</sort>", "<sort>asc</sort>")
> > Else
> > strXML = Replace(strXML, "<sort>asc</sort>", "<sort>desc</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
>
>
Back to top
Display posts from previous:   
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> Programming VBA All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum