PDA

View Full Version : Outlook VBA: Create shortcut to folder



SanderV
08-04-2015, 04:48 AM
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

gmayor
08-04-2015, 11:52 PM
It should be fairly straightforward. What is the Outlook folder path?

SanderV
08-05-2015, 05:16 AM
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

gmayor
08-05-2015, 06:35 AM
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)