VBA/Excel/Access/Word/Outlook/Outlook NameSpace — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 12:47, 26 мая 2010

Accessing Default Folders within the NameSpace Object

 
"olFolderCalendar, 
Sub folder()
    Dim myCal As MAPIFolder
    Set myCal = Application.GetNamespace("MAPI") _
        .GetDefaultFolder(FolderType:=olFolderCalendar)
End Sub



Accessing Other Folders within the NameSpace Object

 
"A list of all the folders contained in the namespace:
Sub List_All_NameSpace_Folders()
    Dim myNS As NameSpace
    Dim myFolder As MAPIFolder
    Dim mySubfolder As MAPIFolder
    strFolderList = "Your Outlook NameSpace contains these folders:" 
    Set myNS = Application.GetNamespace("MAPI")
    With myNS
        For Each myFolder In myNS.Folders
            strFolderList = strFolderList & myFolder.Name & vbCr
            For Each mySubfolder In myFolder.Folders
                Debug.Print mySubfolder.Name 
            Next mySubfolder
        Next myFolder
    End With
End Sub



Creating a New Folder

 
Sub newFolder()
    Application.GetNamespace("MAPI").GetDefaultFolder(olFolderTasks) _
        .Folders.Add Name:="Personal Tasks", Type:=olFolderTasks
End Sub



Deleting a Folder

 
Sub delete()
    Application.GetNamespace("MAPI").GetDefaultFolder(olFolderTasks) _
        .Folders("Personal Tasks").Delete
End Sub



olFolderContacts

 
Sub folder()
    Dim myCal As MAPIFolder
    Set myCal = Application.GetNamespace("MAPI") _
        .GetDefaultFolder(FolderType:=olFolderContacts)
End Sub



olFolderDeletedItems,

 
Sub folder()
    Dim myCal As MAPIFolder
    Set myCal = Application.GetNamespace("MAPI") _
        .GetDefaultFolder(FolderType:=olFolderDeletedItems)
End Sub



olFolderDrafts,

 
Sub folder()
    Dim myCal As MAPIFolder
    Set myCal = Application.GetNamespace("MAPI") _
        .GetDefaultFolder(FolderType:=olFolderDrafts)
End Sub



olFolderInbox,

 
Sub folder()
    Dim myCal As MAPIFolder
    Set myCal = Application.GetNamespace("MAPI") _
        .GetDefaultFolder(FolderType:=olFolderInbox)
End Sub



olFolderJournal,

 
Sub folder()
    Dim myCal As MAPIFolder
    Set myCal = Application.GetNamespace("MAPI") _
        .GetDefaultFolder(FolderType:=olFolderJournal)
End Sub



olFolderNotes,

 
Sub folder()
    Dim myCal As MAPIFolder
    Set myCal = Application.GetNamespace("MAPI") _
        .GetDefaultFolder(FolderType:=olFolderNotes)
End Sub



olFolderOutbox,

 
Sub folder()
    Dim myCal As MAPIFolder
    Set myCal = Application.GetNamespace("MAPI") _
        .GetDefaultFolder(FolderType:=olFolderOutbox)
End Sub



olFolderSentMail,

 
Sub folder()
    Dim myCal As MAPIFolder
    Set myCal = Application.GetNamespace("MAPI") _
        .GetDefaultFolder(FolderType:=olFolderSentMail)
End Sub



olFolderTasks,

 
Sub folder()
    Dim myCal As MAPIFolder
    Set myCal = Application.GetNamespace("MAPI") _
        .GetDefaultFolder(FolderType:=olFolderTasks)
End Sub



olPublicFoldersAllPublicFolders.

 
Sub folder()
    Dim myCal As MAPIFolder
    Set myCal = Application.GetNamespace("MAPI") _
        .GetDefaultFolder(FolderType:=olPublicFoldersAllPublicFolders)
End Sub



Returns the NameSpace and uses the CurrentUser property to display the name of the current user in a message box:

 
Sub current()
    MsgBox Application.GetNamespace("MAPI").CurrentUser
End Sub



Understanding General Methods for Working with Outlook Objects

 
Sub display()
    Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Display
End Sub



Using the NewMail Event and NewMailEx Event

 
Sub Application_NewMail()
    If MsgBox("You have new mail. Do you want to see your Inbox?", _
        vbYesNo + vbInformation, "New Mail Alert") = vbYes Then
        Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Display
    End If
End Sub