Consulting

Results 1 to 12 of 12

Thread: button shortcut to display public folder

  1. #1

    Question button shortcut to display public folder

    Hi,

    I have a basic understanding of Outlook VBA, but what I want to achieve is, as I understand, fairly simple.

    I would like to create a button which when pressed shows a particular Public Folder. I have some code that allows me to find and return a unique ID for a given public folder, which is the first part solved. I also have some code which shows the correct folder. The code is...

    Private Sub GetFolderFromID() 
       Dim olfolder As Outlook.MAPIFolder
       Dim olapp As Outlook.Application
       Set olapp = CreateObject("Outlook.Application")
       Set olfolder = olapp.GetNamespace("Mapi").GetFolderFromID("InsertEntryIDHere")
       olfolder.Display
       Set olfolder = Nothing 
       Set olapp = Nothing
    End Sub
    The only problem with this code is it opens a new and separate Outlook application session, where I would prefer it to open in the current session. How can I tweak my code to show in the current session instead?

    Many thanks
    Last edited by Bob Phillips; 04-15-2014 at 06:00 AM. Reason: Added VBA tags

  2. #2
    yes work with the application object, rather than creating a new one

    change to
    set olapp = applicaton

  3. #3
    Quote Originally Posted by westconn1 View Post
    yes work with the application object, rather than creating a new one

    change to
    set olapp = applicaton
    Thanks. I changed the line as you suggest, but I still get another outlook session opening. I have looked at other similar code, which uses the line...

    Application.ActiveExplorer.CurrentFolder =

    ...which looks like it might do the job I want. Could this be used somewhere?

  4. #4
    Can anyone else help with this? On top of the problem about opening a new session, I'm also having problems making a working 'button' out of this. I have customised my toolbar, which I am familiar with. I have added a button and assigned it to the macro for opening the public folder. However, when you close and open Outlook fresh, the button doesn't work. You press it, but it does nothing. Only if I navigate manually and click on the public folder, then move away to another folder, does the button then start working. It'll continue working until I close and reopen Outlook. Weird!

  5. #5
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    Try Set myOlApp = GetObject(, "Outlook.Application")

    To reference a Public Folder http://blogs.msdn.com/b/brijs/archiv...look-2010.aspx
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

  6. #6
    Quote Originally Posted by skatonni View Post
    Try Set myOlApp = GetObject(, "Outlook.Application")

    To reference a Public Folder http://blogs.msdn.com/b/brijs/archiv...look-2010.aspx
    Hi Skatonni,

    Thanks for your reply. However, I'm not sure where to put your code. Does your code prevent Outlook opening another window? If you could give some guidance about where it goes, that would be greatly appreciated.

    Thanks.

  7. #7
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    Replace CreateObject with GetObject

    http://support.microsoft.com/kb/288902

    Private Sub GetFolderFromID()
    Dim olfolder As Outlook.MAPIFolder
    Dim olapp As Outlook.Application
    
    Set olapp = GetObject(, "Outlook.Application")
    
    ReferencePublicFolders_2010
    
    Set olfolder = olapp.GetNamespace("Mapi").GetFolderFromID("InsertEntryIDHere")
    
    olfolder.Display
    
    Set olfolder = Nothing
    Set olapp = Nothing
    End Sub
    
    Sub ReferencePublicFolders_2010()
    '
    ' Use exact name of top level Public Folder to reference in 2010
    '
    Dim olNS As Namespace
    Dim pub As MAPIFolder
    Set olNS = Application.GetNamespace("MAPI")
    Set pub = olNS.Folders("Public Folders - name @ place.com")
    Set olNS = Nothing
    Set pub = Nothing
    End Sub
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

  8. #8
    Thanks again Skatonni.

    I have copied and pasted your code but it still causes Outlook to open in a new window. I have assigned the macro to a custom toolbar button and I am launching it from there. Even if I execute the code from the VBA editor it still causes a separate Outlook window to open.

    Bizarre.

  9. #9
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    I had not recreated the situation before. I have now. Try this code which sets the Current Folder instead.

    Private Sub GetFolderFromID()
        Dim olapp As Outlook.Application
        Set olapp = CreateObject("Outlook.Application")
        Set myolapp.ActiveExplorer.CurrentFolder = Application.GetNamespace("Mapi").GetFolderFromID("InsertEntryIDHere")
        Set olapp = Nothing
    End Sub
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

  10. #10
    Thanks. When I try that I get error "object required" on the 4th line. I noticed "Set myolapp..." is not declared. Does it need to be?

  11. #11
    it is a typo, drop the my

  12. #12
    Quote Originally Posted by westconn1 View Post
    it is a typo, drop the my
    Perfect. Thanks, this worked a charm! The public folder now opens in the existing Outlook session, rather than opening a new one.

    Thanks to all that helped.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •