有没有办法在excel VBA脚本中突出显示失败的单元格



有没有办法在excel VBA脚本中突出显示失败的单元格?它在outlook中发送电子邮件,但当它在outlook通讯簿中找不到我的工作表中的相应名称时,它会跳过那一行,手动检查实际上不是一个选项,因为我的excel工作表已经包含500多行。我可以添加一行来突出显示地址不正确的行吗?

快速搜索给了我这个功能:

Function CheckAddressExists(eAddress As String) As Boolean
Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim olContactFolder As Outlook.MAPIFolder
Dim olContact As Outlook.ContactItem
Dim olItems As Outlook.Items
Dim bFound As Boolean, bStarted As Boolean
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set olApp = CreateObject("Outlook.Application")
bStarted = True
End If
Set olNS = olApp.GetNamespace("MAPI")
Set olContactFolder = olNS.GetDefaultFolder(10)
Set olItems = olContactFolder.Items
For Each olContact In olItems
bFound = False
If eAddress = olContact.Email1Address Or _
eAddress = olContact.Email2Address Or _
eAddress = olContact.Email3Address Then
bFound = True
Exit For
End If
Err.Clear
Next olContact
If bFound Then
CheckAddressExists = True
End If
CleanUp:
If bStarted = True Then
olApp.Quit
End If
Set olItems = Nothing
Set olNS = Nothing
Set olContactFolder = Nothing
Set olContact = Nothing
End Function

假设在发送邮件的循环中,您可以通过首先在该函数中运行地址来检查地址是否存在,如果不存在,请突出显示地址。

这段代码没有经过我的测试,因为我没有一个宏来发送邮件,如果你想帮助你将任何东西整合到你所拥有的东西中,你需要共享你正在使用的代码。

最新更新