我正在尝试删除Word文档中的水印。
我正在尝试用宏删除后面的文本形状/图像。

For Each s In ActiveDocument.Shapes
s.Select
If Selection.ShapeRange.WrapFormat.Type = wdWrapBehind Then s.Delete
Next发布于 2020-05-12 11:45:22
Word所说的水印不是在文档正文中格式化为“文本后面”的形状。相反,它们是文档标题中的shape对象。没有简单的方法来区分文档标题中的水印和可能存在的其他形状对象,因为水印可以由各种不同的形状类型组成。有了这个警告,尝试下面的宏来删除使用文本效果的内置水印:
Sub Demo()
Application.ScreenUpdating = False
Dim HdFt As HeaderFooter, Shp As Shape
For Each HdFt In ActiveDocument.Sections.First.Headers
For Each Shp In HdFt.Shapes
If Shp.Type = msoTextEffect Then
Shp.Delete
End If
Next
Next
Application.ScreenUpdating = True
End Sub发布于 2020-05-12 09:35:32
你的代码对我来说工作得很好,它会删除所有用文字包装的图片。你确定这些水印是真的shape object吗?Ms word具有水印的built-in功能。
如果你想以编程方式删除它,已经有了codes available (这增加了保护,所以你必须对它进行修补)。它变得越来越复杂,不仅仅是形状,因为它是一个Word building block object。
为了简单起见,这里有一些代码可以让你深入了解如果它是一个水印对象该怎么做。您可以计算标题形状以删除所有相应的索引,或者您将知道Word随机命名的所有标题的名称列表。(我使用宏录制器快速回答了一些代码,主要是所有的.Select方法)
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader 'header mode
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes(1).Select 'Select the first shape from headers (possibly a watermark)
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument 'normal mode
ActiveDocument.Sections(1).Range.Select 'selects section 1
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.Shapes.AddTextEffect(PowerPlusWaterMarkObject44576390, "CUSTOM WATERMARK", "Calibri", 1, False, False, 0, 0).Select 'Create a custom watermark
Selection.ShapeRange.Name = "PowerPlusWaterMarkObject44576390" 'weird name created automatically by MS Word
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes(1).Delete 'delete header shape by index ".Shapes(1).Delete"
Selection.HeaderFooter.Shapes("PowerPlusWaterMarkObject44576390").Delete 'deleting knowing the name请记住,如果水印是其他对象,这可能不起作用。
希望你会发现它很有用!
https://stackoverflow.com/questions/61741663
复制相似问题