跳至主要内容

如何从Outlook联系人电话号码中删除国家代码?

Author: Kelly Last Modified: 2025-05-07

在联系人窗口中,当您点击电话号码前的“商务”/“家庭”/“传真”/“手机”字段按钮以激活“检查电话号码”对话框时(如下图所示),国家代码将自动添加到电话号码之前。但有时国家代码可能完全没必要,并且您可能希望将其从所有电话号码中删除。请尝试以下解决方案:


从联系人的电话号码中删除国家代码

如果您只需要从某个联系人的一个电话号码中删除国家代码,可以手动删除它,操作步骤如下:

1. 在“人员”(或“联系人”)视图中,点击“视图”>“更改视图”>“电话”。见截图:

doc-contacts-remove-country-code-1

2. 双击打开要删除国家代码的联系人电话号码。

3. 在打开的联系人窗口中,从“电话号码”部分的指定电话字段中删除加号和国家代码,然后点击“联系人”>“保存并关闭”。

doc-contacts-remove-country-code-2

至此,国家代码已从指定的电话号码中删除,如下图所示:

doc-contacts-remove-country-code-4


使用VBA从联系人电话号码中删除国家代码

如果需要从Outlook中所有联系人的所有电话号码中删除国家代码,可以应用VBA轻松处理。

1. 在“人员”(或“联系人”)视图中,打开要从所有联系人中删除国家代码的联系人文件夹。

2. 同时按下“Alt”+“F11”键以打开“Microsoft Visual Basic for Applications”窗口。

3. 点击“插入”>“模块”,然后将以下VBA代码粘贴到新打开的模块脚本中。

VBA:从所有联系人的所有电话号码中删除国家代码

Sub FixPhoneFormat()

 Dim oFolder As MAPIFolder
Set oFolder = Application.ActiveExplorer.CurrentFolder

 If Left(UCase(oFolder.DefaultMessageClass), 11) <> "IPM.CONTACT" Then
MsgBox "You need to select a Contacts folder", vbExclamation
Exit Sub
End If

Dim nCounter As Integer
nCounter = 0

Dim oItem
For Each oItem In oFolder.Items
Dim oContact As ContactItem

          If TypeName(oItem) <> "DistListItem" Then
Set oContact = oItem
With oContact
.AssistantTelephoneNumber = FixFormatUSPhone(.AssistantTelephoneNumber)
.Business2TelephoneNumber = FixFormatUSPhone(.Business2TelephoneNumber)
.BusinessFaxNumber = FixFormatUSPhone(.BusinessFaxNumber)
.BusinessTelephoneNumber = FixFormatUSPhone(.BusinessTelephoneNumber)
.CallbackTelephoneNumber = FixFormatUSPhone(.CallbackTelephoneNumber)
.CarTelephoneNumber = FixFormatUSPhone(.CarTelephoneNumber)
.CompanyMainTelephoneNumber = FixFormatUSPhone(.CompanyMainTelephoneNumber)
.Home2TelephoneNumber = FixFormatUSPhone(.Home2TelephoneNumber)
.HomeFaxNumber = FixFormatUSPhone(.HomeFaxNumber)
.HomeTelephoneNumber = FixFormatUSPhone(.HomeTelephoneNumber)
.ISDNNumber = FixFormatUSPhone(.ISDNNumber)
.MobileTelephoneNumber = FixFormatUSPhone(.MobileTelephoneNumber)
.OtherFaxNumber = FixFormatUSPhone(.OtherFaxNumber)
.OtherTelephoneNumber = FixFormatUSPhone(.OtherTelephoneNumber)
.PagerNumber = FixFormatUSPhone(.PagerNumber)
.PrimaryTelephoneNumber = FixFormatUSPhone(.PrimaryTelephoneNumber)
.RadioTelephoneNumber = FixFormatUSPhone(.RadioTelephoneNumber)
.TelexNumber = FixFormatUSPhone(.TelexNumber)
.TTYTDDTelephoneNumber = FixFormatUSPhone(.TTYTDDTelephoneNumber)

.Save

nCounter = nCounter + 1
End With
End If
Next

MsgBox nCounter & " contacts processed.", vbInformation

End Sub

Private Function FixFormatUSPhone(Phone As String) As String

Phone = Trim(Phone)
FixFormatUSPhone = Phone
If Phone = "" Then Exit Function
Dim prefix As String
prefix = Left(Phone, 1)

Do While (prefix = "+" Or prefix = "1")
Phone = Mid(Phone, 3)
prefix = Left(Phone, 1)
Loop

Phone = Replace(Phone, "(", "")
Phone = Replace(Phone, ")", "")
Phone = Replace(Phone, ".", "")
Phone = Replace(Phone, " ", "")
Phone = Replace(Phone, "-", "")

FixFormatUSPhone = Phone

End Function

4. 按下“F5”或点击“运行”按钮以执行VBA。

5. 然后会弹出一个对话框,显示已处理了多少联系人。请点击“确定”按钮关闭它。

doc-contacts-remove-country-code-5

现在,您将看到所有联系人的各种电话号码中的国家代码已被删除。见截图:

doc-contacts-remove-country-code-6


相关文章