C# Snippets
Delete
Public Sub TOC_Delete(ByRef objDocument As Word.Document, _
ByVal sDocumentType As String, _
Optional ByVal bInformUser As Boolean = False)
Dim bdocumentprotected As Boolean
Dim oRange As Word.Range
Dim iStart As Integer
Dim iEnd As Integer
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Sub
If (modSpecific.Document_IsValidAndProtected(objDocument) = True) Then
bdocumentprotected = True
Call modWordObjectModel.Document_Unprotect(objDocument, gsDOCUMENTPASSWORD, False)
End If
If objDocument.TablesOfContents.Count > 0 And _
modWordObjectModel.Bookmark_Exists(objDocument, "BC_TOC_START") = False Then
Call modMessages.TOC_BookmarkMissingDeleteManually("BC_TOC_START")
Exit Sub
End If
If objDocument.TablesOfContents.Count > 0 And _
modWordObjectModel.Bookmark_Exists(objDocument, "BC_TOC_END") = False Then
Call modMessages.TOC_BookmarkMissingDeleteManually("BC_TOC_END")
Exit Sub
End If
If (modWordObjectModel.TOC_Exists(objDocument) = True) Then
iStart = objDocument.Bookmarks("BC_TOC_START").Start
iEnd = objDocument.Bookmarks("BC_TOC_END").End
oRange = objDocument.Range(Start:=CType(iStart, Object), _
End:=CType(iEnd, Object))
oRange.Select()
oRange.Delete()
objDocument.Bookmarks("BC_TOC_START").Delete()
objDocument.Bookmarks("BC_TOC_END").Delete()
gApplicationWord.Selection.Delete(Unit:=Word.WdUnits.wdCharacter, Count:=1)
If (bInformUser = True) Then
Call modMessages.TOC_Deleted()
End If
Else
Call modMessages.TOC_DoesNotExist()
End If
Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
Finally
If (bdocumentprotected = True) Then
Call modWordObjectModel.Document_Protect(objDocument, gsDOCUMENTPASSWORD, False)
End If
End Try
End Sub
Exists
Public Function References_CaptionExists(ByRef objDocument As Word.Document, _
ByVal sCaptionName As String) As Boolean
Dim objCaptionLabel As Word.CaptionLabel
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Function
Return False
For Each objCaptionLabel In gApplicationWord.CaptionLabels
If objCaptionLabel.Name = sCaptionName Then
Return True
End If
Next objCaptionLabel
Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
End Try
End Function
Exists
Public Function TOC_Exists(ByRef objDocument As Word.Document, _
Optional ByVal bInformUser As Boolean = False) As Boolean
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Function
If (objDocument.TablesOfContents.Count > 0) Then
Return True
Else
If (bInformUser = True) Then
Call modMessages.TOC_DoesNotExist()
End If
Return False
End If
Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
End Try
End Function
Figure_Insert
Public Sub Figure_Insert(ByRef objDocument As Word.Document)
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Sub
gApplicationWord.Selection.TypeText(Text:="Figures")
gApplicationWord.Selection.Style = objDocument.Styles("B-TOC Section Heading No Break")
gApplicationWord.Selection.Collapse()
With objDocument.Styles("TOC 4")
.AutomaticallyUpdate = True
.BaseStyle = "B-TOC Figures"
.NextParagraphStyle = "Normal"
End With
With objDocument
.TablesOfContents.Add(Range:=gApplicationWord.Selection.Range, _
RightAlignPageNumbers:=True, _
UseHeadingStyles:=False, _
IncludePageNumbers:=True, _
AddedStyles:="B-Chart Title,2,B-Chart Title. Full Width,2,B-Table Title,2,B-Table Title. Full Width,2,B-Chart Holder Title,2", _
UseHyperlinks:=True, _
HidePageNumbersInWeb:=True, _
UseOutlineLevels:=False)
.TablesOfContents.Format = Word.WdTocFormat.wdTOCTemplate
End With
Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
End Try
End Sub
Insert
Public Function Caption_Insert(ByRef objDocument As Word.Document, _
ByVal sStyleName As String) As Word.Range
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Return Nothing : Exit Function
If (objDocument Is Nothing) Then objDocument = Document_GetActive()
If modWordObjectModel.Caption_Exists(objDocument, "Figure") = False Then
gApplicationWord.CaptionLabels.Add(Name:="Figure")
End If
With gApplicationWord.CaptionLabels("Figure")
.NumberStyle = Word.WdCaptionNumberStyle.wdCaptionNumberStyleArabic
.IncludeChapterNumber = False
End With
With gApplicationWord.Selection
.InsertCaption(Label:="Figure", _
TitleAutoText:="InsertCaption1", _
Title:="", _
Position:=Word.WdCaptionPosition.wdCaptionPositionBelow)
.Style = objDocument.Styles(sStyleName)
.TypeText(Text:=": [Caption]")
.HomeKey(Unit:=Word.WdUnits.wdLine, _
Extend:=Word.WdMovementType.wdExtend)
Return gApplicationWord.Selection.Range
.EndKey(Unit:=Word.WdUnits.wdLine)
End With
Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
Return Nothing
End Try
End Function
Insert
Public Sub HeaderFooter_FootnoteInsert(ByRef objDocument As Word.Document)
Dim bDocumentWasProtected As Boolean
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Sub
If (modSpecific.Document_IsValidAndProtected(objDocument) = True) Then
bDocumentWasProtected = True
Call modWordObjectModel.Document_Unprotect(objDocument, gsDOCUMENTPASSWORD, False)
End If
gApplicationWord.Selection.Footnotes.Add(Range:=gApplicationWord.Selection.Range, _
Reference:="")
gApplicationWord.Selection.Expand(Word.WdUnits.wdParagraph)
If (gApplicationWord.Selection.Sections(1).Index = 1) Then
If (Style_ExistsInDocument(objDocument, "FootnoteWide") = True) Then
gApplicationWord.Selection.Style = objDocument.Styles("FootnoteWide")
End If
gApplicationWord.Selection.Sections(1).PageSetup.BottomMargin = gApplicationWord.InchesToPoints(0.88)
End If
If (gApplicationWord.Selection.Sections(1).Index > 1) Then
If (Style_ExistsInDocument(objDocument, "Footnote Text") = True) Then
gApplicationWord.Selection.Style = objDocument.Styles("Footnote Text")
End If
gApplicationWord.Selection.Sections(1).PageSetup.BottomMargin = gApplicationWord.InchesToPoints(0.88)
End If
gApplicationWord.Selection.Collapse(Word.WdCollapseDirection.wdCollapseStart)
gApplicationWord.Selection.Move(Word.WdUnits.wdWord)
Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
Finally
If (bDocumentWasProtected = True) Then
Call modWordObjectModel.Document_Protect(objDocument, gsDOCUMENTPASSWORD, False)
End If
End Try
End Sub
Insert
Public Sub TOC_Insert(ByRef objDocument As Word.Document, _
ByVal iLevel As Integer, _
ByVal bIncludeFigures As Boolean)
Dim objCurrentPageFit As Word.WdPageFit
Dim iCurrentViewPercentage As Integer
Dim bdocumentprotected As Boolean
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Sub
If (modSpecific.Document_IsValidAndProtected(objDocument) = True) Then
bdocumentprotected = True
Call modWordObjectModel.Document_Unprotect(objDocument, gsDOCUMENTPASSWORD, False)
End If
objCurrentPageFit = gApplicationWord.ActiveWindow.ActivePane.View.Zoom.PageFit
iCurrentViewPercentage = gApplicationWord.ActiveWindow.ActivePane.View.Zoom.Percentage
gApplicationWord.ActiveWindow.ActivePane.View.Zoom.PageFit = Word.WdPageFit.wdPageFitFullPage
If (objDocument.TablesOfContents.Count > 0) Then
Call modMessages.TOC_AlreadyExists()
Exit Sub
End If
If (gApplicationWord.Selection.PageSetup.RightMargin < 200) Then
Call modWordObjectModel.TOC_InsertLevel(objDocument, iLevel)
If (bIncludeFigures = True) Then
Call modWordObjectModel.TOC_InsertFigures(objDocument)
End If
End If
If (gApplicationWord.Selection.PageSetup.RightMargin > 200) Then
Call modWordObjectModel.TOC_InsertLevel(objDocument, iLevel)
End If
gApplicationWord.Selection.Bookmarks.Add(Range:=gApplicationWord.Selection.Range, Name:="BC_TOC_END")
gApplicationWord.ActiveWindow.ActivePane.View.Zoom.PageFit = objCurrentPageFit
gApplicationWord.ActiveWindow.ActivePane.View.Zoom.Percentage = iCurrentViewPercentage
Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
Finally
If (bdocumentprotected = True) Then
Call modWordObjectModel.Document_Protect(objDocument, gsDOCUMENTPASSWORD, False)
End If
End Try
End Sub
InsertFigures
Public Sub TOC_InsertFigures(ByRef objDocument As Word.Document)
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Sub
gApplicationWord.Selection.TypeText(Text:="Figures")
gApplicationWord.Selection.Style = objDocument.Styles("B-TOC Section Heading No Break")
gApplicationWord.Selection.Collapse()
With objDocument.Styles("TOC 4")
.AutomaticallyUpdate = True
.BaseStyle = "B-TOC Figures"
.NextParagraphStyle = "Normal"
End With
With objDocument
.TablesOfContents.Add(Range:=gApplicationWord.Selection.Range, _
RightAlignPageNumbers:=True, _
UseHeadingStyles:=False, _
IncludePageNumbers:=True, _
AddedStyles:="B-Chart Title,2,B-Chart Title. Full Width,2,B-Table Title,2,B-Table Title. Full Width,2,B-Chart Holder Title,2", _
UseHyperlinks:=True, _
HidePageNumbersInWeb:=True, _
UseOutlineLevels:=False)
End With
Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
End Try
End Sub
InsertLevel
Public Sub TOC_InsertLevel(ByRef objDocument As Word.Document, _
ByVal iLevel As Integer)
Dim sTOC As String = ""
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Sub
If (objDocument Is Nothing) Then objDocument = Document_GetActive()
modWordObjectModel.TOC_StylesUpdate(objDocument)
If objDocument.Bookmarks.Exists("BC_TOC_START") = True Then
objDocument.Bookmarks("BC_TOC_START").Delete()
End If
If objDocument.Bookmarks.Exists("BC_TOC_END") = True Then
objDocument.Bookmarks("BC_TOC_END").Delete()
End If
Select Case iLevel
Case 1 : sTOC = "B-Section Divider,1,B-Section Divider Landscape,1,B-SectionHeading no break,1,B-Section Heading,1,B-Heading 1. Full Width,1,B-Article Heading,1"
Case 2 : sTOC = "B-Section Divider,1,B-Section Divider Landscape,1,B-Heading 1,2,B-SectionHeading no break,1,B-Section Heading,1,B-Heading 1. Full Width,1,B-Article Heading,1"
Case 3 : sTOC = "B-Section Divider,1,B-Heading 3. Full Width,3,B-Heading 3,3,B-Heading 2. Full Width,3,B-Heading 2,3,B-Heading 1,2,B-SectionHeading no break,1,B-Section Heading,1,B-Heading 1. Full Width,1,B-Article Heading,1"
End Select
'TOC Inner Pages
Select Case True
Case (gApplicationWord.Selection.PageSetup.RightMargin < 200) And _
modWordObjectModel.Selection_IsAtBeginningOfSection() = True
gApplicationWord.Selection.InsertBreak(Type:=Word.WdBreakType.wdSectionBreakNextPage)
gApplicationWord.Selection.MoveUp(Word.WdUnits.wdLine, 1)
gApplicationWord.Selection.Bookmarks.Add(Range:=gApplicationWord.Selection.Range, Name:="BC_TOC_START")
gApplicationWord.Selection.TypeText(Text:="Contents")
gApplicationWord.Selection.Style = objDocument.Styles("B-TOC Section Heading No Break")
gApplicationWord.Selection.Collapse()
With objDocument.Styles("TOC 3")
.AutomaticallyUpdate = True
.BaseStyle = "B-Toc 3"
.NextParagraphStyle = "Normal"
End With
With objDocument.Styles("TOC 2")
.AutomaticallyUpdate = True
.BaseStyle = "B-TOC 2"
.NextParagraphStyle = "Normal"
End With
With objDocument.Styles("TOC 1")
.AutomaticallyUpdate = True
.BaseStyle = "B-TOC 1"
.NextParagraphStyle = "Normal"
End With
With objDocument
.TablesOfContents.Add(Range:=gApplicationWord.Selection.Range, _
RightAlignPageNumbers:=True, _
UseHeadingStyles:=False, _
IncludePageNumbers:=True, _
AddedStyles:=CType(sTOC, Object), _
UseHyperlinks:=True, _
HidePageNumbersInWeb:=True, _
UseOutlineLevels:=False)
End With
'TOC Inner Pages
Case (gApplicationWord.Selection.PageSetup.RightMargin < 200) And _
modWordObjectModel.Selection_IsAtBeginningOfSection() = False
With gApplicationWord.Selection
.MoveUp(Unit:=Word.WdUnits.wdLine, Count:=1)
.MoveEnd(Word.WdUnits.wdParagraph)
.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
.Range.Select()
.InsertBreak(Type:=Word.WdBreakType.wdSectionBreakNextPage)
.MoveUp(Unit:=Word.WdUnits.wdLine, Count:=1)
.MoveEnd(Word.WdUnits.wdParagraph)
.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
.Range.Select()
.Bookmarks.Add(Range:=gApplicationWord.Selection.Range, Name:="BC_TOC_START")
.MoveDown(Unit:=Word.WdUnits.wdLine, Count:=1)
.Expand(Word.WdUnits.wdParagraph)
.Collapse(Word.WdCollapseDirection.wdCollapseStart)
.InsertBreak(Type:=Word.WdBreakType.wdSectionBreakNextPage)
.MoveUp(Unit:=Word.WdUnits.wdLine, Count:=1)
.TypeText(Text:="Contents")
.Style = objDocument.Styles("B-TOC Section Heading No Break")
.Collapse()
End With
With objDocument.Styles("TOC 3")
.AutomaticallyUpdate = True
.BaseStyle = "B-Toc 3"
.NextParagraphStyle = "Normal"
End With
With objDocument.Styles("TOC 2")
.AutomaticallyUpdate = True
.BaseStyle = "B-TOC 2"
.NextParagraphStyle = "Normal"
End With
With objDocument.Styles("TOC 1")
.AutomaticallyUpdate = True
.BaseStyle = "B-TOC 1"
.NextParagraphStyle = "Normal"
End With
'Application.DoEvents()
With objDocument
.TablesOfContents.Add(Range:=gApplicationWord.Selection.Range, _
RightAlignPageNumbers:=True, _
UseHeadingStyles:=False, _
IncludePageNumbers:=True, _
AddedStyles:=CType(sTOC, Object), _
UseHyperlinks:=True, _
HidePageNumbersInWeb:=True, _
UseOutlineLevels:=False)
.TablesOfContents.Format = Word.WdTocFormat.wdTOCTemplate
End With
'TOC Cover Page
Case (gApplicationWord.Selection.PageSetup.RightMargin > 200)
gApplicationWord.Selection.Bookmarks.Add(Range:=gApplicationWord.Selection.Range, Name:="BC_TOC_START")
With objDocument.Styles("TOC 3")
.AutomaticallyUpdate = True
.BaseStyle = "A-Toc 3"
.NextParagraphStyle = "Normal"
End With
With objDocument.Styles("TOC 2")
.AutomaticallyUpdate = True
.BaseStyle = "A-TOC 2"
.NextParagraphStyle = "Normal"
End With
With objDocument.Styles("TOC 1")
.AutomaticallyUpdate = True
.BaseStyle = "A-TOC 1"
.NextParagraphStyle = "Normal"
End With
With objDocument
.TablesOfContents.Add(Range:=gApplicationWord.Selection.Range, _
RightAlignPageNumbers:=True, _
UseHeadingStyles:=False, _
IncludePageNumbers:=True, _
AddedStyles:=CType(sTOC, Object), _
UseHyperlinks:=True, _
HidePageNumbersInWeb:=True, _
UseOutlineLevels:=False)
End With
End Select
Call modWordObjectModel.Fields_Update(objDocument)
Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex, _
"There was a problem while creating the TOC", , False)
End Try
End Sub
StylesExists
Public Function TOC_StylesExists(ByRef objDocument As Word.Document, _
Optional ByVal bInformUser As Boolean = False) As Boolean
Dim oStyle As Word.Style
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Function
oStyle = objDocument.Styles("A-TOC 1")
oStyle = objDocument.Styles("A-TOC 2")
oStyle = objDocument.Styles("A-Toc 3")
Return True
Catch ex As System.Exception
If (bInformUser = True) Then
'there are styles missing from this document
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex, _
"This document does not contain the following three styles: A-TOC 1, A-TOC 2, A-Toc 3")
End If
Return False
End Try
End Function
StylesUpdate
Public Sub TOC_StylesUpdate(ByRef objDocument As Word.Document)
Dim oStyle As Word.Style
Dim oStyle2 As Word.Style
Dim oStyle3 As Word.Style
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Sub
If Not (Style_ExistsInDocument(objDocument, "A-TOC 1") And _
Style_ExistsInDocument(objDocument, "A-TOC 2") And _
Style_ExistsInDocument(objDocument, "A-TOC 3")) Then
oStyle = objDocument.Styles.Add("A-TOC 1")
With oStyle
.BaseStyle = "B-TOC 1"
.ParagraphFormat.LeftIndent = 0
.ParagraphFormat.TabStops.ClearAll()
.ParagraphFormat.TabStops.Add(gApplicationWord.CentimetersToPoints(12.06), Word.WdTabAlignment.wdAlignTabRight, Word.WdTabLeader.wdTabLeaderSpaces)
End With
oStyle2 = objDocument.Styles.Add("A-TOC 2")
With oStyle2
.BaseStyle = "B-TOC 2"
.ParagraphFormat.LeftIndent = 0
.ParagraphFormat.TabStops.ClearAll()
.ParagraphFormat.TabStops.Add(gApplicationWord.CentimetersToPoints(12.06), Word.WdTabAlignment.wdAlignTabRight, Word.WdTabLeader.wdTabLeaderDots)
End With
oStyle3 = objDocument.Styles.Add("A-Toc 3")
With oStyle3
.BaseStyle = "B-Toc 3"
.ParagraphFormat.LeftIndent = gApplicationWord.CentimetersToPoints(0.43)
.ParagraphFormat.TabStops.ClearAll()
.ParagraphFormat.TabStops.Add(gApplicationWord.CentimetersToPoints(12.06), Word.WdTabAlignment.wdAlignTabRight, Word.WdTabLeader.wdTabLeaderDots)
End With
End If
Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
End Try
End Sub
TOC_AlreadyExists
Public Sub TOC_AlreadyExists()
Dim smessage As String = ""
smessage = "A Table of Contents already exists in this document."
System.Windows.Forms.MessageBox.Show(smessage, _
My.Settings.APP_WINFORMS_TITLE & " - TOC Already", _
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
TOC_BookmarkMissingDeleteManually
Public Sub TOC_BookmarkMissingDeleteManually(ByVal sBookmarkName As String)
Dim smessage As String = ""
smessage = "The bookmark '" & sBookmarkName & "' does not exist in this document." & _
System.Environment.NewLine & _
"You will have to remove the Table of Contents manually."
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
TOC_CannotChangeOrientation
Public Sub TOC_CannotChangeOrientation()
Dim smessage As String = ""
smessage = "You cannot change the orientation of a TOC Page."
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
TOC_Deleted
Public Sub TOC_Deleted()
Dim smessage As String = ""
smessage = "The Table of Contents has been removed from this document."
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
TOC_DoesNotExist
Public Sub TOC_DoesNotExist()
Dim smessage As String = ""
smessage = "This document does not contain a Table of Contents."
System.Windows.Forms.MessageBox.Show(smessage, _
My.Settings.APP_WINFORMS_TITLE & " - No TOC Found", _
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
TOC_HasBeenUpdated
Public Sub TOC_HasBeenUpdated()
Dim smessage As String = ""
smessage = "The Table of Contents in this document has been updated."
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
UnlinkFields
Public Sub Figures_UnlinkFields(ByRef objDocument As Word.Document)
Dim oField As Word.Field
Dim ifieldcount As Integer
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Sub
If (objDocument.Fields.Count = 0) Then
Exit Sub
End If
For ifieldcount = objDocument.Fields.Count To 1 Step -1
oField = objDocument.Fields(ifieldcount)
If (oField.Code.Text.IndexOf("SEQ Figure \* ARABIC") > -1) Or _
(oField.Code.Text.IndexOf("REF _Ref") > -1) Then
objDocument.Fields(ifieldcount).Unlink()
End If
Next ifieldcount
Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
End Try
End Sub
Update
Public Sub TOC_Update(ByRef objDocument As Word.Document, _
Optional ByVal bInformUser As Boolean = False)
Dim objTableOfContents As Word.TableOfContents
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Sub
If (objDocument.TablesOfContents.Count > 0) Then
For Each objTableOfContents In objDocument.TablesOfContents
objTableOfContents.Update()
Next objTableOfContents
If (bInformUser = True) Then
Call modMessages.TOC_HasBeenUpdated()
End If
Else
If (bInformUser = True) Then
Call modMessages.TOC_DoesNotExist()
End If
End If
Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
End Try
End Sub
UpdateFields
Public Sub Figures_UpdateFields(ByRef objDocument As Word.Document, _
Optional ByVal bInformUser As Boolean = False)
Dim oField As Word.Field
Dim ifieldcount As Integer
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Sub
If (objDocument.Fields.Count = 0) Then
Exit Sub
End If
'update figure numbers & references
For ifieldcount = 1 To objDocument.Fields.Count
If modWordObjectModel.Field_CodeTextExists(objDocument, ifieldcount) = True Then
oField = objDocument.Fields(ifieldcount)
If (oField.Code.Text.IndexOf("SEQ Figure \* ARABIC") > -1) Or _
(oField.Code.Text.IndexOf("REF _Ref") > -1) Then
objDocument.Fields(ifieldcount).Update()
End If
End If
Next ifieldcount
If (bInformUser = True) Then
Call modMessages.Figures_HaveBeenUpdated()
End If
Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
End Try
End Sub
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top