Watermark in Word

S

Sunny Kang

Hello,
I'm writing a code to insert watermark into the Word file automatically.
The following is my VB .NET code.

For i = 1 To nSecCount
nTop = oDoc.Sections(i).PageSetup.PageHeight - 30
oHF =
oDoc.Sections(i).Footers(Interop.Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage)
oHF.Range.Select()
oShape = oHF.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect1,
szFooterText, "Times New Roman", 1, MsoTriState.msoFalse,
MsoTriState.msoFalse, 0, 0)
With oShape
.Name = "DMWM" & CStr(i) & "F"
.TextEffect.NormalizedHeight = MsoTriState.msoFalse
.Line.Visible = MsoTriState.msoFalse
.Fill.Visible = MsoTriState.msoTrue
.Fill.ForeColor.RGB = 1
.Fill.Transparency = 0
.Fill.Solid()
.Rotation = 0
.LockAspectRatio = MsoTriState.msoFalse
.Height = 5.2
.Width = Len(szFooterText) * 3.5
.RelativeHorizontalPosition =
Interop.Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage
.RelativeVerticalPosition =
Interop.Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionPage
.Left = 25
.Top = nTop
End With
i = i + 1
Next

With the above code I can insert an watermark into almost Word files I have.
But the following error occurs with a few Word files.
"The RelativeHorizontalPosition method or property is not available because
the drawing operation cannot be applied to the current selection."

Any help would be appreciate.
Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top