简体   繁体   English

在非默认Outlook联系人文件夹中创建联系人

[英]Create a contact in a non-default Outlook contact folder

I would like to create a contact in a non-default Outlook contact folder with Excel VBA 2010. 我想使用Excel VBA 2010在非默认Outlook联系人文件夹中创建联系人。

In this example, the folder name is “azerty”, located in 在此示例中,文件夹名称为“ azerty”,位于
\\mypersonnal_pst\\Contacts \\ mypersonnal_pst \\联系

I tried: 我试过了:

Dim myolApp As Outlook.Application
Dim myNamespace As Outlook.Namespace
Set myolApp = CreateObject("Outlook.Application")
Set myNamespace = myolApp.GetNamespace("MAPI")
Set Folder = myNamespace.GetDefaultFolder(olFolderContacts).Parent.Folders("azerty")
Set objContact = myolApp.CreateItem(olContactItem)
With objContact
  .Email1Address = "example@ex.com "
  .FirstName = "Joe"
  .LastName = "Mc"
  .HomeTelephoneNumber = "99 99 99 99 99"
  .HomeAddressCity = "Xlcity"
  .Save
End With

If you need to create an Outlook item in the specific folder use the Add method of the Items class instead. 如果需要在特定文件夹中创建Outlook项目,请使用Items类的Add方法。

Dim myolApp As Outlook.Application
Dim myNamespace As Outlook.Namespace
Set myolApp = CreateObject("Outlook.Application")
Set myNamespace = myolApp.GetNamespace("MAPI")
Set Folder = myNamespace.GetDefaultFolder(olFolderContacts).Parent.Folders("azerty")
Set objContact = Folder.Items.Add(olContactItem)
With objContact
  .Email1Address = "example@ex.com "
  .FirstName = "Joe"
  .LastName = "Mc"
  .HomeTelephoneNumber = "99 99 99 99 99"
  .HomeAddressCity = "Xlcity"
  .Save
End With

Or move the item to the target folder using the Move method after creation. 或在创建后使用Move方法将项目移动到目标文件夹。

Dim myolApp As Outlook.Application
Dim myNamespace As Outlook.Namespace
Set myolApp = CreateObject("Outlook.Application")
Set myNamespace = myolApp.GetNamespace("MAPI")
Set Folder = myNamespace.GetDefaultFolder(olFolderContacts).Parent.Folders("azerty")
Set objContact = myolApp.CreateItem(olContactItem)
With objContact
  .Email1Address = "example@ex.com "
  .FirstName = "Joe"
  .LastName = "Mc"
  .HomeTelephoneNumber = "99 99 99 99 99"
  .HomeAddressCity = "Xlcity"
  .Save
  .Move Folder 
End With

You can read more about that in the How To: Create a new Outlook Contact item programmatically article. 您可以在“ 如何:以编程方式创建新的Outlook联系人”文章中了解有关此内容的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM