VBA/Excel/Access/Word/Outlook/Outlook NameSpace

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

Accessing Default Folders within the NameSpace Object

   <source lang="vb">

"olFolderCalendar, Sub folder()

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

End Sub

</source>
   
  


Accessing Other Folders within the NameSpace Object

   <source lang="vb">

"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

</source>
   
  


Creating a New Folder

   <source lang="vb">

Sub newFolder()

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

End Sub

</source>
   
  


Deleting a Folder

   <source lang="vb">

Sub delete()

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

End Sub

</source>
   
  


olFolderContacts

   <source lang="vb">

Sub folder()

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

End Sub

</source>
   
  


olFolderDeletedItems,

   <source lang="vb">

Sub folder()

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

End Sub

</source>
   
  


olFolderDrafts,

   <source lang="vb">

Sub folder()

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

End Sub

</source>
   
  


olFolderInbox,

   <source lang="vb">

Sub folder()

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

End Sub

</source>
   
  


olFolderJournal,

   <source lang="vb">

Sub folder()

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

End Sub

</source>
   
  


olFolderNotes,

   <source lang="vb">

Sub folder()

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

End Sub

</source>
   
  


olFolderOutbox,

   <source lang="vb">

Sub folder()

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

End Sub

</source>
   
  


olFolderSentMail,

   <source lang="vb">

Sub folder()

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

End Sub

</source>
   
  


olFolderTasks,

   <source lang="vb">

Sub folder()

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

End Sub

</source>
   
  


olPublicFoldersAllPublicFolders.

   <source lang="vb">

Sub folder()

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

End Sub

</source>
   
  


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

   <source lang="vb">

Sub current()

   MsgBox Application.GetNamespace("MAPI").CurrentUser

End Sub

</source>
   
  


Understanding General Methods for Working with Outlook Objects

   <source lang="vb">

Sub display()

   Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Display

End Sub

</source>
   
  


Using the NewMail Event and NewMailEx Event

   <source lang="vb">

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

</source>