问题描述
我有下面的VBScript,它应该为文档的所有页面添加水印。目前它只将水印添加到第一页,即使我指定它应该添加到所有部分。问题是Word奇怪地处理水印。
如果我打开文档并添加水印,它只会被添加到第一页。如果我将水印添加到第二页,则第一页水印消失并且水印被添加到所有其他页面。第一页和第二页标题不是
链接,我猜这是导致问题,但我不知道如何解决这个问题。在这种情况下,如果您想要在Word中为所有页面添加水印,那么您似乎只有两个选项。要么自定义水印,要么将
水印从一个部分复制粘贴到另一个部分。两种情况都会以某种方式欺骗Word做正确的事情。所以我的问题是我如何通过VBScript做到这一点?
I have the below VBScript which is supposed to add a watermark to all pages of a document. Currently it only adds the watermark to the first page even though I specify that it should add to all sections. The issue is what Word handles watermarks weirdly. If I open the document and add a watermark it only gets added to the first page. If I add the watermark to the second page, the first page watermark disappears and the watermark is added to all the other pages. The first page and second page headers are not linked, which I guess is causing the issue, but I don't know how to get around that. It seems that in this case you only have two options if you wanted to add a watermark to all the pages from within Word. Either do a custom watermark or copy and paste the watermark from one section to the other. Both cases somehow trick Word into doing the right thing. So my question is how do I do this through VBScript?
这是我目前的代码:
Function AddWatermark
Dim shp, fp, hdr, skip
For count = 1 to 3
found = False ' indicates if we should skip adding the watermark because it already exists
Set pageHeader = myDocument.Sections(count).Headers(1)
Set shapes = pageHeader.Shapes
' loop through all shapes in the header and remove any watermarks that were added by the user
' if we find out watermark already, set a flag so we don't add a second one.
For Each shape in shapes
If InStr(shape.Name, "PowerPlusWaterMarkObject") = 1 Or ( InStr(shape.Name, "WordArt") = 1 And shape.AlternativeText <> "In Review" ) Then
' If someone added a watermark through the Word interface, remove it
shape.Delete
ElseIf shape.AlternativeText = "In Review" Then
' if the watermark already exists, skip adding it
found = True
End If
Next
If Not found then
' if we didn't find a watermark add one
Set shp = shapes.AddTextEffect(1, "In Review", "Arial", 1, True, False, 0, 0)
With shp
.TextEffect.NormalizedHeight = False
.Line.Visible = False
.Fill.Visible = True
.Fill.Solid
.Fill.ForeColor.RGB = RGB(192, 192, 192)
.Fill.Transparency = 0.5
.Rotation = 325
.LockAspectRatio = True
.Height = wrd.InchesToPoints(1.33)
.Width = wrd.InchesToPoints(7.55)
.WrapFormat.AllowOverlap = True
.WrapFormat.Side = 3
.WrapFormat.Type = 3
.RelativeHorizontalPosition = 0
.RelativeVerticalPosition = 0
.Left = -999995
.Top = -999995
End With
End If
Next
End Function
推荐答案
您的脚本没有任何问题,但我怀疑您的word文档中有多个部分。水印仅添加到当前部分。
There is nothing wrong with your script but I suspect that you have more than one section in your word document. The water mark gets added to the current section only.
这篇关于VBScript为Word文档添加水印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!