ContactItem 方法 (Outlook)ContactItem.AddPicture method (Outlook)

向联系人项目添加图片。Adds a picture to a contact item.


expressionexpression. AddPicture( _Path_ )

_表达式_一个代表ContactItem对象的变量。expression A variable that represents a ContactItem object.


名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
路径Path 必需Required StringString 一个字符串, 包含要添加到联系人项目的图片的完整路径和文件名。A string containing the complete path and file name of the picture to be added to the contact item.


如果联系人项目已附有图片,此方法将覆盖现有图片。If the contact item already has a picture attached to it, this method will overwrite the existing picture.

图片可以是图标、GIF、JPEG、BMP、TIFF、WMF、EMF 或 PNG 文件。The picture can be an icon, GIF, JPEG, BMP, TIFF, WMF, EMF, or PNG file. Microsoft Outlook 会对图片自动进行必要的大小调整。Microsoft Outlook will automatically perform the necessary resizing of the picture.


以下 Microsoft Visual Basic for Applications (VBA) 示例提示用户指定联系人姓名和含有联系人图片的文件名称,然后将图片添加到联系人项目。The following Microsoft Visual Basic for Applications (VBA) example prompts the user to specify the name of a contact and the file name containing a picture of the contact, and then adds the picture to the contact item. 如果联系人项目图片已经存在,将提示用户是否用新文件覆盖现有图片。If a picture already exists for the contact item, the example prompts the user to specify if the existing picture should be overwritten by the new file.

Sub AddPictureToAContact() 
 Dim myNms As Outlook.NameSpace 
 Dim myFolder As Outlook.Folder 
 Dim myContactItem As Outlook.ContactItem 
 Dim strName As String 
 Dim strPath As String 
 Dim strPrompt As String 
 Set myNms = Application.GetNamespace("MAPI") 
 Set myFolder = myNms.GetDefaultFolder(olFolderContacts) 
 strName = InputBox("Type the name of the contact: ") 
 Set myContactItem = myFolder.Items(strName) 
 If myContactItem.HasPicture = True Then 
 strPrompt = MsgBox("The contact already has a picture associated with it. Do you want to overwrite the existing picture?", vbYesNo) 
 If strPrompt = vbNo Then 
 Exit Sub 
 End If 
 End If 
 strPath = InputBox("Type the file name for the contact: ") 
 myContactItem.AddPicture (strPath) 
 End Sub

另请参阅See also

创建 ContactItem 对象ContactItem Object

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.