Adding Header Text in Different Sections

P

Praful

Hello All,
I have to add Header text to all the sections available in the Document with
different First page, Even Odd and Primary settings. But i am not able to do
that as it behaves abnormally by putting Header Text in some pages and
leaving some of them. I am coding in vb.net and here is my code.

For Each Section In DocObj.Sections
AppObj.ActiveWindow.ActivePane.View.SeekView =
WdSeekView.wdSeekCurrentPageHeader
For Each MyShape In
Section.Headers(WdHeaderFooterIndex.wdHeaderFooterPrimary).Shapes
'If (DocObj.PageSetup.DifferentFirstPageHeaderFooter = False) Then
If (InStr(MyShape.Name, "WordWaterMark") <> 0) Then
MyShape.Delete()
Next

For Each Header In Section.Headers
AddWaterMarkSections(WatermarkText, Header, Section)
Next
Next

Try
AppObj.ActiveWindow.View.SeekView =
Microsoft.Office.Interop.Word.WdSeekView.wdSeekMainDocument
Catch e As Exception
End Try
next
End sub


Private Sub AddWaterMark Sections
ShapeName = "WordWaterMark" & WSection.Index & "_" & WHeader.Index
WHeader.Range.Select()
If WText = "" Then Exit Sub


AppObj.Selection.HeaderFooter.Shapes.AddTextEffect(Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect1, _
"--- " & WText & " ---", "Times New Roman", 8, False, False, 30,
50).Select()
With AppObj.Selection.ShapeRange
.Name = ShapeName
'.TextEffect.FontSize = 30
.Rotation = 315
.Line.DashStyle =
Microsoft.Office.Core.MsoLineDashStyle.msoLineSolid
.Line.Weight = 0.5
.Fill.Solid()
.Fill.ForeColor.RGB = RGB(255, 0, 0)
.Line.ForeColor.RGB = RGB(255, 0, 0)
.LockAspectRatio = True
'.RelativeHorizontalPosition =
WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin
'.wdRelativeHorizontalPositionPage
'.RelativeVerticalPosition =
WdRelativeVerticalPosition.wdRelativeVerticalPositionPage
.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoBringToFront)
.Fill.Transparency = 0.0
End With

Catch e As Exception
MsgBox("Word not able to add the Classifiacation. Please contact
administrator", MsgBoxStyle.MsgBoxRight + MsgBoxStyle.Critical)
End Try
End Sub
 
C

Chuck

Your code is very hard to read because it wraps very poorly.

Why are there brackets after MyShape.Delete()?

Is the syntax of Private Sub AddWaterMark Sections correct?

There doesn't appear to be any Shape.Add code in your AddWarterMark sub (but
again, it's really hard to read your code).
 
M

McX

Hi Praful

On this line :
AppObj.Selection.HeaderFooter.Shapes.AddTextEffect(...)
the AddTextEffect method must have an Anchor argument because the Shapes
collection is common to all the headers / footers.

However, as I posted in the microsoft.public.word.vba.customization group,
there must be a bug with AddTextEffect when used in headers / footers and I
don't know the workaround. You can try for example the AddTextbox with the
Anchor argument and it will work fine (yes, I know that it's not what you
need - this is just to show you the bug in AddTextEffect).

Maybe someone else in the group knows the workaround to insert a WordArt in
the right place ?

McX
 

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