Outlook Macro to Change Views

Hi - I need to write a macro in Outlook 2010 to toggle between two saved Views, as follows:

Assume the saved Views are called "View 1" and "View 2". To change from the current View to "View 1" manually I would type:

Click Tab 'View' > Click "Change View" > Click "View 1" from the list of saved views

I want a macro which has the following effect:
Case 1: If View 1 is current view the macro should change the view to View 2
Case 2: If View 2 is current view the macro should change the view to View 1
Case 3: if neither View 1 nor View 2 is the current view the macro should change the view to View 1

Can anyone assist with this?
MikeCEOAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
HI,

pls try something like this
Sub Macro()
    Set objName = Application.GetNamespace("MAPI")
    Set objViews = objName.GetDefaultFolder(olFolderInbox).Views
    Set ActiveView = Application.ActiveExplorer.CurrentView
    If ActiveView.Name = "View1" Then
        objViews("View2").Apply
    Else
        objViews("View1").Apply
    End If

End Sub

Open in new window

Regards
0
MikeCEOAuthor Commented:
Hi - unfortunately this does not seem to work. Running the macro has no visible effect.

Regards,

Mike
0
Rgonzo1971Commented:
Have you changed the View1 and View2  to your views?
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

MikeCEOAuthor Commented:
To test it I renamed the view names to View1 and View2 and simply pasted your text in.
0
Rgonzo1971Commented:
Hi could you try this to see if the macros run

Sub Macro1()
    Set objName = Application.GetNamespace("MAPI")
    Set objviews = objName.GetDefaultFolder(olFolderInbox).Views
    For Each vw In objviews
        Debug.Print vw.Name
    Next
End Sub

Open in new window

0
MikeCEOAuthor Commented:
nothing happens I'm afraid.
0
MikeCEOAuthor Commented:
Alexa I think perhaps you have posted an answer to a different question.
0
Rgonzo1971Commented:
EDIT Could you try to exit from OL and re-enter to see if the macros run then
0
Rgonzo1971Commented:
Which macro setting do you have?
0
FarWestCommented:
try this
Sub Macro()
    If Application.ActiveExplorer.CurrentView.Name = "View1" Then
       Application.ActiveExplorer.CurrentView = "View2"
    Else
        Application.ActiveExplorer.CurrentView = "View1"
    End If

End Sub
                                          

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MikeCEOAuthor Commented:
Thanks FarWest, much appreciated. Works like a charm.

Rgonzo1971 thanks for he;ping.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.