C# Snippets
CanBeChanged
Public Function Section_CanBeChanged(ByRef objDocument As Word.Document, _
ByVal sDocumentTemplate_Code As String, _
Optional ByVal bInformUser As Boolean = True) As Boolean
Dim blnIsValid As Boolean
Dim oSection As Word.Section
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Function
blnIsValid = True
oSection = gApplicationWord.Selection.Sections(1)
'Return True
If ((oSection.Index = 1) And (sDocumentTemplate_Code = clsIdentifyDocumentAs.TemplateCode_Report.ToString)) Then
If (bInformUser = True) Then
Call modMessages.Pages_CannotChangeOrientationCoverPage()
End If
Return False
End If
If (oSection.Index = 2 And _
objDocument.TablesOfContents.Count > 0) Then
If (bInformUser = True) Then
Call modMessages.TOC_CannotChangeOrientation()
End If
Return False
End If
If ((oSection.Index = objDocument.Sections.Count) And _
(sDocumentTemplate_Code = clsIdentifyDocumentAs.TemplateCode_Report.ToString)) Then
If (bInformUser = True) Then
Call modMessages.Sections_CannotChangeOrientationLastSection()
End If
Return False
End If
If (oSection.Index = (objDocument.Sections.Count - 1) And _
oSection.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.Paragraphs.Count > 3) Then
If (bInformUser = True) Then
Call modMessages.Message_General_PageCannotChangeOrientationDisclosurePages()
End If
Return False
End If
If (gApplicationWord.Selection.Sections.Count > 1) Then
If (bInformUser = True) Then
Call modMessages.Sections_CannotChangeOrientationMultipleSections()
End If
Return False
End If
Return blnIsValid
Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
End Try
End Function
ChangeToLandscape
Public Sub App_ToolbarLandscapeSection()
Try
clsError.ErrorFlagChange(False)
gbDEBUG = clsError.DebugFlag("Debug")
Call clsSection.OrientationSet("Landscape")
gApplication.ActiveDocument.PageSetup.LeftMargin = gApplication.MillimetersToPoints(20)
gApplication.ActiveDocument.PageSetup.RightMargin = gApplication.MillimetersToPoints(15)
Dim isectiono As Integer
Dim ipageno As Integer
Dim objcolouredbarshape As Word.Shape
isectiono = CInt(gApplication.Selection.Information(Word.WdInformation.wdActiveEndSectionNumber))
ipageno = CInt(gApplication.Selection.Information(Word.WdInformation.wdActiveEndPageNumber))
gApplication.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekCurrentPageFooter
gApplication.Selection.WholeStory()
objcolouredbarshape = gApplication.Selection.Range.ShapeRange(1)
With objcolouredbarshape.TextFrame.TextRange.ParagraphFormat.TabStops
.ClearAll()
.Add(Position:=gApplication.MillimetersToPoints(287), _
Alignment:=CType(Word.WdTabAlignment.wdAlignTabRight, System.Object), _
Leader:=Word.WdTabLeader.wdTabLeaderSpaces)
End With
gApplication.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekMainDocument
Catch objCOMException As System.Runtime.InteropServices.COMException
gobjCOMException = objCOMException
Catch objException As Exception
gobjException = objException
Finally
If gbDEBUG = True Or _
((IsNothing(gobjCOMException) = False Or IsNothing(gobjException) = False)) Then
Call clsError.Handle2("App_ToolbarLandscapeSection", msMODULENAME, _
"change the page orientation to landscape.", _
gobjCOMException, gobjException)
End If
End Try
End Sub
ChangeToPortrait
Public Sub App_ToolbarPortraitSection()
Try
clsError.ErrorFlagChange(False)
gbDEBUG = clsError.DebugFlag("Debug")
Call clsSection.OrientationSet("Portrait")
gApplication.ActiveDocument.PageSetup.LeftMargin = gApplication.MillimetersToPoints(20)
gApplication.ActiveDocument.PageSetup.RightMargin = gApplication.MillimetersToPoints(15)
Dim isectiono As Integer
Dim ipageno As Integer
Dim objcolouredbarshape As Word.Shape
isectiono = CInt(gApplication.Selection.Information(Word.WdInformation.wdActiveEndSectionNumber))
ipageno = CInt(gApplication.Selection.Information(Word.WdInformation.wdActiveEndPageNumber))
gApplication.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekCurrentPageFooter
gApplication.Selection.WholeStory()
objcolouredbarshape = gApplication.Selection.Range.ShapeRange(1)
With objcolouredbarshape.TextFrame.TextRange.ParagraphFormat.TabStops
.ClearAll()
.Add(Position:=gApplication.MillimetersToPoints(200), _
Alignment:=CType(Word.WdTabAlignment.wdAlignTabRight, System.Object), _
Leader:=Word.WdTabLeader.wdTabLeaderSpaces)
End With
gApplication.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekMainDocument
Catch objCOMException As System.Runtime.InteropServices.COMException
gobjCOMException = objCOMException
Catch objException As Exception
gobjException = objException
Finally
If gbDEBUG = True Or _
((IsNothing(gobjCOMException) = False Or IsNothing(gobjException) = False)) Then
Call clsError.Handle2("App_ToolbarPortraitSection", msMODULENAME, _
"change the page orientation to Portrait.", _
gobjCOMException, gobjException)
End If
End Try
End Sub
Insert
Public Shared Sub Insert()
Try
If clsError.ErrorFlag() = True Then Exit Sub
gApplicationWord.Selection.InsertBreak(Type:=Word.WdBreakType.wdSectionBreakNextPage)
Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException
Finally
If gbDEBUG_WORD = True Or _
((Not mobjCOMException Is Nothing) Or (Not mobjException Is Nothing)) Then
Call clsError.Handle("Insert", msCLASSNAME, _
"insert the new section break.", _
mobjCOMException, mobjException)
End If
End Try
End Sub
IsAtBeginningOfSection
Public Function ParaIsAtBeginningOfSection(ByVal oPara As Word.Paragraph) As Boolean
Dim intPreviousSection As Integer
Dim intCurrentSection As Integer
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Function
intCurrentSection = oPara.Range.Sections(1).Index
If intCurrentSection = 1 Then
Return False
Else
intPreviousSection = oPara.Previous(1).Range.Sections.Last.Index
If intPreviousSection < intCurrentSection Then
Return True
Else
Return False
End If
End If
Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
End Try
End Function
OrientationGet
Public Shared Function OrientationGet() As String
Try
If clsError.ErrorFlag() = True Then Exit Function
If gApplicationWord.Selection.PageSetup.Orientation = _
Word.WdOrientation.wdOrientPortrait Then
OrientationGet = "Portrait"
End If
If gApplicationWord.Selection.PageSetup.Orientation = _
Word.WdOrientation.wdOrientLandscape Then
OrientationGet = "Landscape"
End If
Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException
Finally
If gbDEBUG_WORD = True Or _
((Not mobjCOMException Is Nothing) Or (Not mobjException Is Nothing)) Then
Call clsError.Handle("OrientationChange", msCLASSNAME, _
"return the page orientation for the current section.", _
mobjCOMException, mobjException)
End If
End Try
End Function
OrientationSet
Public Shared Sub OrientationSet(ByVal sOrientationType As String)
Try
If clsError.ErrorFlag() = True Then Exit Sub
If sOrientationType = "Portrait" Then
gApplicationWord.Selection.PageSetup.Orientation = _
Word.WdOrientation.wdOrientPortrait
End If
If sOrientationType = "Landscape" Then
gApplicationWord.Selection.PageSetup.Orientation = _
Word.WdOrientation.wdOrientLandscape
End If
Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException
Finally
If gbDEBUG_WORD = True Or _
((Not mobjCOMException Is Nothing) Or (Not mobjException Is Nothing)) Then
Call clsError.Handle("OrientationSet",msCLASSNAME, _
"change the page orientation of the current section.", _
mobjCOMException, mobjException)
End If
End Try
End Sub
Section_DoesNotExist
Public Shared Sub Section_DoesNotExist(ByVal iTotalSections As Integer)
If clsError.ErrorFlag() = True Then Exit Sub
Call System.Windows.Forms.MessageBox.Show( _
"This document does not contain iTotalSections sections." & _
gsCRLF & _
"The active document only contains " & gApplicationWord.ActiveDocument.Sections.Count & " sections.", _
gsSOLUTION_NAME_WORD, _
Windows.Forms.MessageBoxButtons.OK, _
Windows.Forms.MessageBoxIcon.Information)
clsError.ErrorFlagChange(True)
End Sub
'***********************************************************************************
Section_IsProtectedCantGetPageWidth
Public Sub Section_IsProtectedCantGetPageWidth()
Dim smessage As String = ""
smessage = "Unable to return the page width of this section." & _
System.Environment.NewLine & _
System.Environment.NewLine & _
"This section of the document is protected."
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