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.
Who is Participating?
David LeeConnect With a Mentor Commented:
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
        Do While Left(strFolderPath, 1) = "\"
            strFolderPath = Right(strFolderPath, Len(strFolderPath) - 1)
        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
    End If
    On Error GoTo 0
End Function

Open in new window

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?

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?
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

David LeeCommented:
I believe it will.
chernavskyAuthor Commented:
OK, I'll try it later this afternoon. Won't have time until then.  I'll let you know.  Thanks.
David LeeCommented:
No problem.  You're welcome.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.