首页 > 解决方案 > 在通讯录宏中查找替换

问题描述

我正在尝试构建一个宏来删除散布在 MS Outlook 联系人备注字段中的一系列电子邮件。这是我到目前为止所拥有的,当它执行时,似乎没有任何可见的事情发生。感谢任何反馈。电子邮件看起来像<name@xyz.com>

Sub OutlookDeleteTextBetween()
Dim olInspector As Outlook.Inspector
Dim olDocument As Word.Document
Dim olSelection As Word.Selection

Set olInspector = Application.ActiveInspector()
Set olDocument = olInspector.WordEditor
Set olSelection = olDocument.Application.Selection
olSelection.WholeStory

With olSelection.Find
      .Text = "\<*\>"
      .MatchWildcards = True
      .Replacement.Text = ""
      .Execute Replace:=wdReplaceAll
End With
End Sub

标签: vbaemailoutlookcontacts

解决方案


删除散布在 MS Outlook 联系人备注字段中的一系列电子邮件

进行一些更改后尝试Save邮件项目。在您保存项目或重新打开窗口之前,Outlook 可能不会传播更改。

如果您需要查找附加的邮件项目,它们将作为附件存储在 Outlook 项目中。在您看来,您需要检查Attachments集合并使用Attachments.Remove方法从集合中删除对象。例如:

Sub RemoveAttachmentBeforeForwarding()  
 Dim myinspector As Outlook.Inspector  
 Dim myItem As Outlook.MailItem  
 Dim myattachments As Outlook.Attachments 

 Set myinspector = Application.ActiveInspector  
 If Not TypeName(myinspector) = "Nothing" Then  
   Set myItem = myinspector.CurrentItem.Forward  
   Set myattachments = myItem.Attachments  
   While myattachments.Count > 0  
     myattachments.Remove 1  
   Wend  
   myItem.Display  
   myItem.Recipients.Add "Eugene Astafiev"  
   myItem.Send  
 Else  
   MsgBox "There is no active inspector."  
 End If  
End Sub

推荐阅读