AddToFavorites Method

Microsoft Outlook Visual Basic

AddToFavorites Method

       

Adds the current MAPI folder to the Internet Explorer favorites list.

expression.AddToFavorites(fNoUI, Name)

expression   Required. An expression that returns a MAPIFolder object.

fNoUI  Optional Variant. Specifies that the folder is added without the standard user interface input box. This requires that the Name argument is specified.

Name  Optional Variant. Specifies the name of the favorite folder, if the fNoUI argument is included.

Example

The following example adds the current folder to the Favorites list in Internet Explorer. The subroutine accepts a MAPIFolder object and a String that represents the folder's name in the Favorites list. It executes the AddToFavorites method, using the String value supplied by the user as its argument. The fNoUI argument is not specified, meaning that the user interface will not appear.


Sub FaveChange()

    Dim appolApp As Outlook.Application
    Dim nmsName As NameSpace 'the namespace
    Dim fldFolder As MAPIFolder 'the folder
    Dim strName As String 'user created string

    Set appolApp = Outlook.Application
    'Create instance of namespace
    Set nmsName = appolApp.GetNamespace("Mapi")
    Set fldFolder = nmsName.GetDefaultFolder(olFolderInbox)
    'Prompt user for a Favorites list name
    strName = _
        InputBox("Enter the name of the folder as it will appear in the favorites list.")
    Call FaveList(fldFolder, strName)

End Sub

Sub FaveList(ByRef fldFolder As MAPIFolder, ByVal strName As String)
'Add a Folder object to the Favorites list in Internet Explorer

    'Call method with strName as name argument
    fldFolder.AddToFavorites fNoUI:= True, Name:=strName
    'Display a message to the user
    MsgBox "The folder " & fldFolder.Name & _
           " was added to the Internet Explorer favorites list as " & strName & "."

End Sub