Posting links / URLs to the favourites section of Outlook

siddharthnk

New Member
Joined
Jun 20, 2013
Messages
48
I need your help in creating a distributable add in which will help me post either one or many URL's (predefined by me) to outlooks favorites section. I.e. when I distribute this add in to the user and the user runs it, the url's should be posted to the favorites i.e. the user should be able to click on the links and access the URL's. Any help will be greatly appreciated. Thanks in advance.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Base code for this solution was originally taken from Microsoft years ago.

Code:
Private Sub CreateImportantFavoritesFolder()    
    Dim objNamespace As NameSpace
    Dim objCalendars As Folder
    Dim objFolder As Folder
     
    Dim objPane As NavigationPane
    Dim objModule As MailModule
    Dim objGroup As NavigationGroup
    Dim objNavFolder As NavigationFolder
     
    On Error GoTo ErrRoutine
     
    ' First, retrieve the default Inbox folder.
    Set objNamespace = Application.GetNamespace("MAPI")
    Set objCalendars = objNamespace.GetDefaultFolder(olFolderInbox)
     
    ' Create a new mail folder named "Important Items".
    Set objFolder = objCalendars.Folders.Add("Important Items")
         
    ' Get the NavigationPane object for the
    ' currently displayed Explorer object.
    Set objPane = Application.ActiveExplorer.NavigationPane
     
    ' Get the mail module from the Navigation Pane.
    Set objModule = objPane.Modules.GetNavigationModule(olModuleMail)
     
    ' Get the "Favorite Folders" navigation group from the
    ' mail module.
    With objModule.NavigationGroups
        Set objGroup = .GetDefaultNavigationGroup(olFavoriteFoldersGroup)
    End With
     
    ' Add a new navigation folder for the "Important Items"
    ' folder in the "Favorite Folders" navigation group.
    
    Set objNavFolder = objGroup.NavigationFolders.Add(objFolder)
    With objNavFolder.Folder
        .WebViewURL = "http://www.google.com"
        .WebViewOn = True
    End With
     
EndRoutine:
    On Error GoTo 0
    Set objNavFolder = Nothing
    Set objFolder = Nothing
    Set objGroup = Nothing
    Set objModule = Nothing
    Set objPane = Nothing
    Set objNamespace = Nothing
    Exit Sub
 
ErrRoutine:
    MsgBox Err.Number & " - " & Err.Description, _
        vbOKOnly Or vbCritical, _
        "CreateImportantFavoritesFolder"
End Sub

Adapt as required. The two lines of code you are interested in though are the ones I added in (using a Folder Object):

Code:
.WebViewURL = "http://www.google.com"
.WebViewOn = True

Hope this helps

Simon
 
Upvote 0
Hi Simon, thanks for the solution. I have created a module in an excel macro enabled workbook and pasted the code in a new module to run it from there. When I try to run the code I get an error on the first dim i.e. "objNamespace As Namespace". The error is "Compile error: User-defined type not defined". Pardon me for my ignorance but am I doing something wrong here?
 
Upvote 0
Apologies, when I first read your post I simply assumed it would be an Outlook add-in. I've simply taken the code originally posted and changed it to work in Excel - you might not want all of it but it shows you the mechanics of adding a folder (in this case one you've created) to the favourites and adding a URL to it. You'll need to add a reference to the Outlook Object Library to your project if you haven't done so already. You can do this through going to Tools > References in the VBE and then choosing Microsoft Outlook X.0 Object library where X represents the highest version number of Outlook installed.

Code:
Sub CreateImportantFavoritesFolder()

    Dim objOlApp As Outlook.Application
    Dim objNamespace As Outlook.Namespace
    Dim objCalendars As Outlook.Folder
    Dim objFolder As Outlook.Folder
     
    Dim objPane As Outlook.NavigationPane
    Dim objModule As Outlook.MailModule
    Dim objGroup As Outlook.NavigationGroup
    Dim objNavFolder As Outlook.NavigationFolder
     
    On Error GoTo ErrRoutine
    Set objOlApp = Outlook.Application
    ' First, retrieve the default Inbox folder.
    Set objNamespace = objOlApp.GetNamespace("MAPI")
    Set objCalendars = objNamespace.GetDefaultFolder(olFolderInbox)
     
    ' Create a new mail folder named "Important Items".
    Set objFolder = objCalendars.Folders.Add("Important Items")
         
    ' Get the NavigationPane object for the
    ' currently displayed Explorer object.
    Set objPane = objOlApp.ActiveExplorer.NavigationPane
     
    ' Get the mail module from the Navigation Pane.
    Set objModule = objPane.Modules.GetNavigationModule(olModuleMail)
     
    ' Get the "Favorite Folders" navigation group from the
    ' mail module.
    With objModule.NavigationGroups
        Set objGroup = .GetDefaultNavigationGroup(olFavoriteFoldersGroup)
    End With
     
    ' Add a new navigation folder for the "Important Items"
    ' folder in the "Favorite Folders" navigation group.
    
    Set objNavFolder = objGroup.NavigationFolders.Add(objFolder)
    With objNavFolder.Folder
        .WebViewURL = "http://www.google.com"
        .WebViewOn = True
    End With
     
EndRoutine:
    On Error GoTo 0
    Set objNavFolder = Nothing
    Set objFolder = Nothing
    Set objGroup = Nothing
    Set objModule = Nothing
    Set objPane = Nothing
    Set objNamespace = Nothing
    Set objOlApp = Nothing
    Exit Sub
 
ErrRoutine:
    MsgBox Err.Number & " - " & Err.Description, _
        vbOKOnly Or vbCritical, _
        "CreateImportantFavoritesFolder"
End Sub

Simon
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top