C# Snippets


Footer_UpdateFirstPage

Public Sub Footer_UpdateFirstPage(ByRef objDocument As Word.Document, _
ByVal sDocumentType As String)

Dim objRange As Word.Range
Dim objStyle As Word.Style
Dim iPageNumber As Integer
Dim sDisclaimer As String
Dim strOriginalStyle As String

Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Sub

iPageNumber = modWordObjectModel.Document_LastPageWithContent(objDocument)

objRange = objDocument.Sections(1).Footers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range
objStyle = CType(objRange.Style, Word.Style)
strOriginalStyle = objStyle.NameLocal.ToString

If strOriginalStyle = "Footer" Then
objRange = objDocument.Sections(1).Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range
objStyle = CType(objRange.Style, Word.Style)
strOriginalStyle = objStyle.NameLocal.ToString
End If

objRange.Delete()
objRange.MoveEndWhile(Cset:=System.Convert.ToChar(7), Count:=Word.WdConstants.wdBackward)

If (iPageNumber > 0) Then
objRange.Text = sDisclaimer.Replace("[xx]", CType(iPageNumber, String))
End If

If strOriginalStyle.IndexOf("FirstPageFooter") > -1 Or _
strOriginalStyle.ToUpper.IndexOf("A") > -1 Then

objRange.Style = strOriginalStyle
Else

If (sDocumentType = clsIdentifyDocumentAs.DocumentType_BarCap.ToString) Then
With objRange.Font
.Name = "Expert Sans Extra Bold"
.Size = 7.5
.Spacing = -0.1
End With
End If

If (sDocumentType = clsIdentifyDocumentAs.DocumentType_Legacy.ToString) Then
With objRange.Font
.Name = "Arial"
.Size = 9
End With
With objRange.Paragraphs(1)
.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
.Borders(Word.WdBorderType.wdBorderTop).LineStyle = Word.WdLineStyle.wdLineStyleSingle
.Borders(Word.WdBorderType.wdBorderTop).LineWidth = Word.WdLineWidth.wdLineWidth050pt
.Borders(Word.WdBorderType.wdBorderTop).Color = Word.WdColor.wdColorBlack
End With
End If
End If

Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
Finally
objDocviewUploadService2 = Nothing
End Try
End Sub

Header_Insert

Public Sub Header_Insert(ByRef objDocument As Word.Document, _
ByVal sHeaderText As String)

Dim isectioncount As Integer
Dim objSection As Word.Section

Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Sub

For isectioncount = 1 To objDocument.Sections.Count - 1

objSection = CType(objDocument.Sections(isectioncount), Word.Section)
objSection.Headers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.Tables(1).Cell(1, 3).Range.Text = sHeaderText

Next isectioncount

Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
End Try
End Sub

Message_HeadersFooters_ExitFirst

Public Sub HeadersFooters_ExitFirst()

Dim smessage As String = ""

smessage = "You must come out of the header/footer before you can do this."

System.Windows.Forms.MessageBox.Show(smessage, _
My.Settings.APP_WINFORMS_TITLE, _
System.Windows.Forms.MessageBoxButtons.OK, _
System.Windows.Forms.MessageBoxIcon.Information)

smessage = smessage & " (" & System.Reflection.MethodBase.GetCurrentMethod.Name & ")"

Call Tracer_Add2("MESSAGE", smessage.Replace(System.Environment.NewLine, " ").Replace(" ", " "))
End Sub

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top