【发布时间】:2020-06-29 15:21:41
【问题描述】:
我正在尝试搜索选定的电子邮件并删除附件。我做了一些研究,最终选择了 Word.Document 路线。
我之前有一段代码删除了所有附件,但留下了一个虚线框,表示图像不可用。
我正在尝试将两者网格化,因为下面的这个不会删除附件,而只会删除内联形状。
删除内联图像的代码:
Sub DeleteAllAttachmentsFromSelectedMessages()
Dim selectedItems As Selection
Dim messageObject As Object
Dim documentsObject As Object
Dim shp As InlineShape
Dim doc As Object
Dim shpRange As Object
Const wdInlineShapePicture As Long = 3
Const wdInlineShapesEmbeddedOLEObject As Long = 1
' Set reference to the Selection.
Set selectedItems = ActiveExplorer.Selection
For Each messageObject In selectedItems
Set doc = messageObject.GetInspector.WordEditor
' doc.UnProtect
For Each shp In doc.InlineShapes
Select Case shp.Type
Case wdInlineShapePicture, wdInlineShapesEmbeddedOLEObject
Set shpRange = doc.Range(shp.Range.Characters.First.Start, shp.Range.Characters.Last.End)
shpeRange.Text = "Attachment Removed" ' Replace shape with text
Case Else
' Other shapes not supported yet
End Select
' doc.Protect
messageObject.Save
Next
Next
MsgBox "Attachments were removed.", vbOKOnly, "Message"
Set selectedItems = Nothing
Set messageObject = Nothing
Set documentsObject = Nothing
Set shp = Nothing
Set doc = Nothing
Set shpRange = Nothing
End Sub
对于我用来删除所有附件的代码:
Sub DeleteAllAttachmentsFromSelectedMessages()
Dim attachmentsObject As Attachments
Dim selectedItems As Selection
Dim messageObject As Object
Dim attachmentCount As Long
Set selectedItems = ActiveExplorer.Selection
For Each messageObject In selectedItems
Set attachmentsObject = messageObject.Attachments
attachmentCount = attachmentsObject.Count
While attachmentCount > 0
attachmentsObject(1).Delete
attachmentCount = attachmentsObject.Count
Wend
messageObject.Save
Next
MsgBox "Attachments were removed.", vbOKOnly, "Message"
Set attachmentsObject = Nothing
Set selectedItems = Nothing
Set messageObject = Nothing
End Sub
【问题讨论】:
-
您可以添加您所谈论的内联图像