Consulting

Results 1 to 4 of 4

Thread: Outlook VBA: Create shortcut to folder

  1. #1
    VBAX Newbie
    Joined
    Aug 2015
    Posts
    2
    Location

    Outlook VBA: Create shortcut to folder

    Hello,

    Is there a VBA way to create a shortcut to a folder in Outlook? Pressing ctrl-7 you can access the shortcut-list. I want to automatically create a shortcut to a specific folder in a quite comprehensive folder tree we use for our projects.

    Thanks,
    Sander


  2. #2
    It should be fairly straightforward. What is the Outlook folder path?
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Newbie
    Joined
    Aug 2015
    Posts
    2
    Location
    Thanks for your reply. This is the problem. We have shared e-mail (public folders) for all of our projects (thousands each year). This way of course everybody can see all the project mails if necessary. If I need to put a mail in the correct project folder, I need to scroll down the whole tree.

    For instants …\GL_Proj\2015\0xxx\05xx\051x\0510. For project 20150510.

    Although I love climbing trees outside, I hate to go through a big folder tree on my computer to reach the right folder. Therefor I thought of making shortcuts for each of the projects I’m involved with.
    Using VBA: Inputbox -> type the project number -> shortcut is created. Something like that.
    The script for the first part is ready. But I can’t figure out how to actually create a shortcut in Outlook using VBA.


    Other (VBA of non VBA) solutions are welcome of course.

    Thanks,
    Sander

  4. #4
    The basic code for shared or personal folders is:
    Sub GetFolder()
    Dim strFolder As String
    Dim olNS As Outlook.NameSpace
    Dim olRecipient As Outlook.Recipient
    Dim iFolder As Outlook.Folder
    Dim olMsg As MailItem
        On Error Resume Next
        Set olNS = Application.GetNamespace("MAPI")
        Set olRecipient = olNS.CreateRecipient("Dan Wilson")
        'Set olMsg = ActiveExplorer.Selection.Item(1)
        strFolder = InputBox("Project?")
        If strFolder = "" Then GoTo lbl_Exit
        Set iFolder = olNS.GetSharedDefaultFolder(olRecipient, olFolderInbox).folders(strFolder)
        'Set iFolder = olNS.GetDefaultFolder(olFolderInbox).folders(strFolder)
        iFolder.Display
        'olMsg.Move iFolder
    lbl_Exit:
        Set olNS = Nothing
        Set olRecipient = Nothing
        Set iFolder = Nothing
        Set olMsg = Nothing
        Exit Sub
    End Sub
    You don't have to display the folder to move a message to it so I have included code to move the message. The important bit is the path here

    olNS.GetSharedDefaultFolder(olRecipient, olFolderInbox).folders(strFolder)

    In the example I have just used one level below the inbox, whereas you have at least 5 so you would have to split up the value from the input box (I am not going to try and work out the logic there) and add the folders to the tree e.g

    olNS.GetSharedDefaultFolder(olRecipient, olFolderInbox).folders(strFolder1).folders(strFolder2).folders(strFolder3). folders(strFolder4).folders(strFolder5)
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

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