Office-VBA-联系人FileAs名称

问题描述 投票:0回答:1

我使用以下文档修复了现有联系人的FileAs条目,但不适用于仅是公司名称的联系人。

https://docs.microsoft.com/en-us/office/vba/outlook/concepts/address-book/programmatically-change-the-display-format-for-all-contacts

因为名字和姓氏字段为空,所以FileAs条目为空白(“” +“” +“”)。

如何调整代码以运行for循环,以查找空白的FileAs字段并将CompanyName字段设置为FileAs字段?

vba outlook contacts
1个回答
0
投票

将会是这样:

Set contactItems = items.Restrict("[MessageClass]='IPM.Contact'")
For Each itemContact In contactItems
'The underscore on the line below breaks the line into two lines.
'You need the left side of the equals for each condition in the if cant do or " "
    If itemContact.Firstname = "" Or itemContact.Firstname = " " _
    Or itemContact.lastname = "" or itemContact.lastname = " " Then
        itemContact.FileAs = itemContact.Company
        itemContact.Save
    end if
Next
© www.soinside.com 2019 - 2024. All rights reserved.