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
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