Startup macro in Outlook 2007 to open non-default inbox folder

I have two PST files associated with my Outlook 2007 (I'm running Windows XP Pro).   As it stands now, upon startup, I automatically go into the inbox of the default PST.  But that's not what I want.

I would like a macro that automatically runs on start-up and switches me to the inbox of the non-default PST.  Actually, I'm not wedded to using a macro -- if there is some other way to accomplish the same goal, then I'm all ears.

Thanks in advance.  I love Experts Exchange!  You guys always come up with solutions to the most intractable problems.
chernavskyAsked:
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.

chernavskyAuthor Commented:
OK, I figured out how to do this myself, but there is still a problem.

To set the start-up folder, you can go to Tools -> Options -> Other -> Advanced Options  -> "Startup in this folder:"

That just about does what I want it to do, but there's one annoying problem.  The folder-view sidebar along the left-hand side isn't displaying the proper PST -- it shows the default PST.  I still have to scroll down to view the folders for the non-default PST.

Any way to change this?

Thanks!
0
David LeeCommented:
Hi, chernavsky.

The code below will do what you've asked for.  Follow these instructions to add the code to Outlook.

1.  Start Outlook
2.  Click Tools > Macro > Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
4.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's VB Editor window
5.  Edit the code as needed.  I included comment lines wherever something needs to or can change
6.  Click the diskette icon on the toolbar to save the changes
7.  Close the VB Editor
8.  Click Tools > Trust Center
9.  Click Macro Security
10. Set Macro Security to "Warnings for all macros"
11. Click OK
12. Close Outlook
13. Start Outlook.  Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run.  Say yes.

Private Sub Application_Startup()
    'Change the folder path on the next line'
    Set Application.ActiveExplorer.CurrentFolder = OpenOutlookFolder("Personal Folders\Inbox")
End Sub

Function OpenOutlookFolder(strFolderPath As String) As Outlook.MAPIFolder
    ' Purpose: Opens an Outlook folder from a folder path.'
    ' Written: 4/24/2009'
    ' Author:  BlueDevilFan'
    ' Outlook: All versions'
    Dim arrFolders As Variant, _
        varFolder As Variant, _
        bolBeyondRoot As Boolean
    On Error Resume Next
    If strFolderPath = "" Then
        Set OpenOutlookFolder = Nothing
    Else
        Do While Left(strFolderPath, 1) = "\"
            strFolderPath = Right(strFolderPath, Len(strFolderPath) - 1)
        Loop
        arrFolders = Split(strFolderPath, "\")
        For Each varFolder In arrFolders
            Select Case bolBeyondRoot
                Case False
                    Set OpenOutlookFolder = Outlook.Session.Folders(varFolder)
                    bolBeyondRoot = True
                Case True
                    Set OpenOutlookFolder = OpenOutlookFolder.Folders(varFolder)
            End Select
            If Err.Number <> 0 Then
                Set OpenOutlookFolder = Nothing
                Exit For
            End If
        Next
    End If
    On Error GoTo 0
End Function

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
chernavskyAuthor Commented:
BlueDevilFan, thanks so much.  Before I enter your macro, can I ask if the code will also cause the folder-view or mail-view sidebar to scroll down to the proper PST?
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

David LeeCommented:
I believe it will.
0
chernavskyAuthor Commented:
OK, I'll try it later this afternoon. Won't have time until then.  I'll let you know.  Thanks.
0
David LeeCommented:
No problem.  You're welcome.
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.