Posting links / URLs to the favourites section of Outlook

siddharthnk

New Member
Joined
Jun 20, 2013
Messages
44
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.
 

s.ridd

Board Regular
Joined
Nov 23, 2012
Messages
178
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
 

siddharthnk

New Member
Joined
Jun 20, 2013
Messages
44
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?
 

s.ridd

Board Regular
Joined
Nov 23, 2012
Messages
178
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
 

Forum statistics

Threads
1,081,991
Messages
5,362,595
Members
400,683
Latest member
LogChief

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top