Remove filter from current view - outlook 2003

Status
Not open for further replies.
Q

Q2hyaXMgUXVheWxl

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!
 
K

Ken Slovak - [MVP - Outlook]

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().

"Chris Quayle" <Chris Quayle> 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!
 
Q

Q2hyaXMgUXVheWxl

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
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().

> >

>

> "Chris Quayle" <Chris Quayle> 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!


>
 
K

Ken Slovak - [MVP - Outlook]

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.

"Chris Quayle" <ChrisQuayle> 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
 
Q

Q2hyaXMgUXVheWxl

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.
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.

> >

>

> "Chris Quayle" <ChrisQuayle> 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


>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
C-S-R Manage Add-ins (Remove Wunderlist) Using Outlook 0
O Remove duplicates within two accounts Using Outlook 2
D How to remove a folder, option grayed out Using Outlook 4
T Outlook 2016 remove envelope icon for certain folders Using Outlook 5
M In Outlook Calendar remove the buttons: 'Today' and '<' (Back a day) and '>' (Forward a day) that are below the Ribbon and above the calendar display. Using Outlook 0
P [SOLVED] Auto remove [EXTERNAL] from subject Using Outlook 16
P Add, remove, & reorder folder pane Using Outlook 6
W Remove specific contacts from contact list Outlook VBA and Custom Forms 3
T Cannot remove needless PST Using Outlook 1
Healy Consultants Macro to remove inside organization distribution list email address when reply to all recepients Outlook VBA and Custom Forms 0
S Unable to remove rule outlook 2010 Using Outlook 0
N How to remove signature formatting from Text in Word (accidentally taken from Outlook) Using Outlook 0
B Remove Subject Residual Outlook VBA and Custom Forms 3
P how to remove unwanted PST file default categories assigned to many calendar entries Using Outlook 7
J Remove text to Clean Up Outlook VBA and Custom Forms 1
B Automatically Forward Emails and Remove/Replace All or Part of Body Outlook VBA and Custom Forms 8
D Remove text in subject using VBA Outlook VBA and Custom Forms 4
T Remove Old Location From Tasks Pane Using Outlook 1
A remove or turn off outlook.com contact folder from outlook 2016 Using Outlook 4
R Chancing / remove “ something ” in the subject, online archive Outlook VBA and Custom Forms 8
Morgan Fowler Remove Signature Using Outlook 1
M How to remove a list of specific contacts from Outlook Using Outlook 18
R New Links on Navigation Pane, How to Remove? Using Outlook 1
M VBA to remove deferred delivery on a MeetingItem Outlook VBA and Custom Forms 2
J Remove extra line above signature in reply Outlook VBA and Custom Forms 5
Diane Poremsky How to Remove RSS Support from Outlook New Slipstick.com Articles 0
Diane Poremsky Remove Attachments From Messages New Slipstick.com Articles 0
Diane Poremsky Remove Office 2013 Update Banner New Slipstick.com Articles 0
O Remove duplicate mail items Outlook VBA and Custom Forms 6
Diane Poremsky Remove a password from an Outlook *.pst File New Slipstick.com Articles 3
G VBA/Macro to remove page colour when replying or forwarding email Outlook VBA and Custom Forms 2
L Fake reminder apperaring (not in calendar) - how to remove? Using Outlook 5
J Your IMAP server wants to alert you to the following: cannot remove system folder Using Outlook 3
A Auto Insert of filename when selecting 'Remove Attachment' Using Outlook 1
C how to remove icons on right hand side outlook 2013 Using Outlook 2
K Remove Manage APPS button for users Exchange Server Administration 1
P Remove name and parenthses from email Using Outlook 1
G Outlook calendar entry corrupted. Constant pop up when you open outlook. Unable to delete or remove. Using Outlook 2
Diane Poremsky How to remove the primary account from Outlook 2010/2013 New Slipstick.com Articles 0
Diane Poremsky Remove an Address from Reply All New Slipstick.com Articles 0
Diane Poremsky Remove Outlook apps from Outlook New Slipstick.com Articles 0
L An () has been inserted after the address in an address box; how do I remove them. Using Outlook 1
S How to remove forms from Organizational forms library Outlook VBA and Custom Forms 2
2 Task has a strike through but is not complete - how to remove? Using Outlook 1
A Is it possible to remove the word Categories: from task list views? Using Outlook 2
W URGENT Cancel and remove imported pop3 mails Using Outlook 6
Emerogork How do I remove "Delete Folder" from the right-click menu? Using Outlook 1
T How to remove annoying Big Blue Type at beginning of my messages Using Outlook 2
H Cannot remove unwanted fields from form Outlook VBA and Custom Forms 9
T How to remove "automatically delete messages form this sender"? Using Outlook 1

Similar threads

Top