C# Snippets


Active

public static string Active()
{
try
{
if (clsError.ErrorFlag() == true)
return;

Word.View objPane;
string stemp;

objPane = gApplicationWord.ActiveWindow.ActivePane.View;

switch (objPane.Type)
{
case object _ when Word.WdViewType.wdMasterView:
{
stemp = "Master";
break;
}

case object _ when Word.WdViewType.wdNormalView:
{
stemp = "Normal";
break;
}

case object _ when Word.WdViewType.wdOutlineView:
{
stemp = "Outline";
break;
}

case object _ when Word.WdViewType.wdPrintPreview:
{
stemp = "PrintPreview";
break;
}

case object _ when Word.WdViewType.wdPrintView:
{
stemp = "Print";
break;
}

case object _ when Word.WdViewType.wdWebView:
{
stemp = "Web";
break;
}
}

Active = stemp;
}
catch (Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}

finally
{
if (gbDEBUG_WORD == true | ((!mobjCOMException == null) | (!mobjException == null)))
clsError.Handle("Active", msCLASSNAME, "return the type of pane that is currently active.", mobjCOMException, mobjException);
}
}
Public Shared Function Active() As String

Try
If clsError.ErrorFlag() = True Then Exit Function

Dim objPane As Word.View
Dim stemp As String

objPane = gApplicationWord.ActiveWindow.ActivePane.View

Select Case objPane.Type
Case Word.WdViewType.wdMasterView : stemp = "Master"
Case Word.WdViewType.wdNormalView : stemp = "Normal"
Case Word.WdViewType.wdOutlineView : stemp = "Outline"
Case Word.WdViewType.wdPrintPreview : stemp = "PrintPreview"
Case Word.WdViewType.wdPrintView : stemp = "Print"
Case Word.WdViewType.wdWebView : stemp = "Web"
End Select

Active = stemp

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("Active", msCLASSNAME, _
"return the type of pane that is currently active.", _
mobjCOMException, mobjException)
End If
End Try
End Function

DeserializeFrom

public object DocVariable_DeserializeFrom(ref Word.Document objDocument, string sDocVariable, System.Type oDocValue)
{
object myObject;
string strObjectXml;

try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
{
return null; return;
}

strObjectXml = modWordObjectModel.DocVariable_Get(objDocument, sDocVariable, true, false);

if (strObjectXml != "" && strObjectXml != " ")
{
myObject = new object();
myObject = modGeneral.XML_DeserializeFromString(strObjectXml, oDocValue);
return myObject;
}
else
return null;
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
return null;
}
}
Public Function DocVariable_DeserializeFrom(ByRef objDocument As Word.Document, _
ByVal sDocVariable As String, _
ByVal oDocValue As System.Type) As Object
Dim myObject As Object
Dim strObjectXml As String

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

strObjectXml = modWordObjectModel.DocVariable_Get(objDocument, sDocVariable, True, False)

If strObjectXml <> "" AndAlso strObjectXml <> " " Then

myObject = New Object
myObject = modGeneral.XML_DeserializeFromString(strObjectXml, oDocValue)
Return myObject

Else
Return Nothing
End If

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

Doc_Activate

public bool Doc_Activate(ref Word.Document objDocument, bool bInformUser)
{
int icount;

try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

for (icount = 1; icount <= gApplicationWord.Documents.Count; icount++)
{
if ((gApplicationWord.Documents(icount).Name == objDocument.Name))
{
objDocument.Activate();
return true;
return;
}
}

if ((bInformUser == true))
modMessages.Document_ActivateUnsuccessful();
return false;
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
return false;
}
}
Public Function Doc_Activate(ByRef objDocument As Word.Document, _
ByVal bInformUser As Boolean) As Boolean
Dim icount As Integer

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

For icount = 1 To gApplicationWord.Documents.Count
If (gApplicationWord.Documents(icount).Name = objDocument.Name) Then
objDocument.Activate()
Return True
Exit Function
End If
Next icount

If (bInformUser = True) Then
Call modMessages.Document_ActivateUnsuccessful()
End If
Return False

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

Doc_Active

public static bool Active()
{
try
{
if (clsError.ErrorFlag() == true)
return;

if (gApplicationWord.Documents.Count > 0)
Active = true;
else
Active = false;
}
catch (Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}

finally
{
if (gbDEBUG_WORD == true | ((IsNothing(mobjCOMException) == false | IsNothing(mobjException) == false)))
clsError.Handle("Open", "clsDocument", "determine if there is a document active.", mobjCOMException, mobjException);
}
}
Public Shared Function Active() As Boolean

Try
If clsError.ErrorFlag() = True Then Exit Function

If gApplicationWord.Documents.Count > 0 Then
Active = True
Else
Active = False
End If

Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException

Finally
If gbDEBUG_WORD = True Or _
((IsNothing(mobjCOMException) = False Or IsNothing(mobjException) = False)) Then

Call clsError.Handle("Open", "clsDocument", _
"determine if there is a document active.", _
mobjCOMException, mobjException)
End If
End Try
End Function

Doc_Close

public static void Doc_Close(bool bSave, string sDocumentName = "", bool bInformUser = true)
{
Word.Document objdocument;
Word.WdSaveOptions objsaveoptions;

try
{
if (clsError.ErrorFlag() == true)
return;

if (sDocumentName != "")
objDocument = gApplicationWord.Documents(sDocumentName);
else
objDocument = gApplicationWord.ActiveDocument;

if (bSave == true)
objsaveoptions = Word.WdSaveOptions.wdSaveChanges;
if (bSave == false)
objsaveoptions = Word.WdSaveOptions.wdDoNotSaveChanges;

if (gApplicationWord.Documents.Count == 0)
return;

(Word._Document)objdocument.Close(SaveChanges: (Word.WdSaveOptions)objsaveoptions);
}
catch (Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}

finally
{
if (gbDEBUG_WORD == true | ((!mobjCOMException == null) | (!mobjException == null)))
clsError.Handle("CloseDocument", msCLASSNAME, "close the active document.", mobjCOMException, mobjException);
}
}
Public Shared Sub Doc_Close(ByVal bSave As Boolean, _
Optional ByVal sDocumentName As String = "", _
Optional ByVal bInformUser As Boolean = True)

Dim objdocument As Word.Document
Dim objsaveoptions As Word.WdSaveOptions

Try
If clsError.ErrorFlag() = True Then Exit Sub

If sDocumentName <> "" Then
objDocument = gApplicationWord.Documents(sDocumentName)
Else
objDocument = gApplicationWord.ActiveDocument
End If

If bSave = True Then objsaveoptions = Word.WdSaveOptions.wdSaveChanges
If bSave = False Then objsaveoptions = Word.WdSaveOptions.wdDoNotSaveChanges

If gApplicationWord.Documents.Count = 0 Then Exit Sub

Call CType(objdocument, Word._Document).Close(SaveChanges:=CType(objsaveoptions, Word.WdSaveOptions))

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("CloseDocument", msCLASSNAME, _
"close the active document.", _
mobjCOMException, mobjException)
End If
End Try
End Sub

Doc_CloseByName

public void Doc_CloseByName(string sDocName, bool bInformUser = false)
{
int icount;

try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

for (icount = 1; icount <= gApplicationWord.Documents.Count; icount++)
{
if ((gApplicationWord.Documents(icount).Name == sDocName))
{
gApplicationWord.Documents(icount).Close(false);
return;
}
}

if ((bInformUser == true))
{
}
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex, "", false);
}
}
Public Sub Doc_CloseByName(ByVal sDocName As String, _
Optional ByVal bInformUser As Boolean = False)

Dim icount As Integer

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

For icount = 1 To gApplicationWord.Documents.Count
If (gApplicationWord.Documents(icount).Name = sDocName) Then
gApplicationWord.Documents(icount).Close(False)
Exit Sub
End If
Next icount

If (bInformUser = True) Then
'message saying that the document does not exist
End If

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

Doc_FullNameGet

public static string FullNameGet()
{
try
{
if (clsError.ErrorFlag() == true)
return;

FullNameGet = gApplicationWord.ActiveDocument.FullName;
}
catch (Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}

finally
{
if (gbDEBUG_WORD == true | ((IsNothing(mobjCOMException) == false | IsNothing(mobjException) == false)))
clsError.Handle("FullNameGet", "clsDocument", "returns the fullname of the active document.", mobjCOMException, mobjException);
}
}
Public Shared Function FullNameGet() As String

Try
If clsError.ErrorFlag() = True Then Exit Function

FullNameGet = gApplicationWord.ActiveDocument.FullName

Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException

Finally
If gbDEBUG_WORD = True Or _
((IsNothing(mobjCOMException) = False Or IsNothing(mobjException) = False)) Then

Call clsError.Handle("FullNameGet", "clsDocument", _
"returns the fullname of the active document.", _
mobjCOMException, mobjException)
End If
End Try
End Function

Doc_GetActive

public Word.Document Document_GetActive()
{
try
{
return gApplicationWord.ActiveDocument;
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex, "", false);
return null/* TODO Change to default(_) if this is not a reference type */;
}
}
Public Function Document_GetActive() As Word.Document
Try
Return gApplicationWord.ActiveDocument

Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex, _
"", False)
Return Nothing
End Try
End Function

Doc_HasATable

public bool Document_HasATable(ref Word.Document objDocument)
{
try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

if (objDocument.Content.Tables.Count > 0)
return true;
else
return false;
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
}
}
Function Document_HasATable(ByRef objDocument As Word.Document) As Boolean
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Function

If objDocument.Content.Tables.Count > 0 Then
Return True
Else
Return False
End If

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

Doc_HasBeenSaved

public bool Document_HasBeenSaved(ref Word.Document objDocument, bool bInformUser, bool bDisplaySaveAs)
{
try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

// Prompts user to SaveAs, if the doc has not been saved
if ((objDocument.Name != objDocument.FullName))
{
Tracer_Add2("DOCUMENT", "Has Been Saved - " + objDocument.FullName, false);
return true;
return;
}
else
{
if ((bInformUser == true))
{
modMessages.Document_HasNotBeenSaved();
return false;
}

if ((bDisplaySaveAs == true))
{
if ((gApplicationWord.Dialogs(Word.WdWordDialog.wdDialogFileSaveAs).Show() == -1))
return true;
else
return false;
}
else
return false;
}
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
}
}
Public Function Document_HasBeenSaved(ByRef objDocument As Word.Document, _
ByVal bInformUser As Boolean, _
ByVal bDisplaySaveAs As Boolean) As Boolean
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Function

' Prompts user to SaveAs, if the doc has not been saved
If (objDocument.Name <> objDocument.FullName) Then

Call Tracer_Add2("DOCUMENT", "Has Been Saved - " & objDocument.FullName, False)
Return True
Exit Function
Else

If (bInformUser = True) Then
Call modMessages.Document_HasNotBeenSaved()
Return False
End If

If (bDisplaySaveAs = True) Then
If (gApplicationWord.Dialogs(Word.WdWordDialog.wdDialogFileSaveAs).Show() = -1) Then
Return True
Else
Return False
End If
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

Doc_IsDisplayed

public bool Doc_IsDisplayed()
{
try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

if (gApplicationWord.Documents.Count > 0)
return true;
}
catch (Exception ex)
{
return false;
}
}
Public Function Doc_IsDisplayed() As Boolean

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

If gApplicationWord.Documents.Count > 0 Then
Return True
End If

Catch ex As System.Exception
Return False
End Try
End Function

Doc_LastPageWithContent

public int Document_LastPageWithContent(ref Word.Document objDocument)
{
int iEndAdjustedPageNumber;
int iLastPageNumber;

try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

if (modSpecific.TableExists(objDocument))
{
iLastPageNumber = System.Convert.ToInt32(oAnalystCertRange.Information(Word.WdInformation.wdActiveEndPageNumber));

if ((iLastPageNumber == 0))
{
iEndAdjustedPageNumber = System.Convert.ToInt32(objDocument.Content.Information(Word.WdInformation.wdActiveEndAdjustedPageNumber));
iLastPageNumber = (iEndAdjustedPageNumber - 2);
}
}

if (iLastPageNumber > 0)
iLastPageNumber -= 1;

return iLastPageNumber;
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
}
}
Public Function Document_LastPageWithContent(ByRef objDocument As Word.Document) As Integer

Dim iEndAdjustedPageNumber As Integer
Dim iLastPageNumber As Integer

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

If modSpecific.TableExists(objDocument) Then

iLastPageNumber = CType(oAnalystCertRange.Information(Word.WdInformation.wdActiveEndPageNumber), Integer)

If (iLastPageNumber = 0) Then
iEndAdjustedPageNumber = CType(objDocument.Content.Information(Word.WdInformation.wdActiveEndAdjustedPageNumber), Integer)
iLastPageNumber = (iEndAdjustedPageNumber - 2)
End If
End If

If iLastPageNumber > 0 Then iLastPageNumber -= 1

Return iLastPageNumber

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

Doc_NewDocument

public static Word.Document NewDocument(zBET_enNewDocumentType enNewDocumentType, string sFolderPath, string sFileName, string sExtension = ".dot", string sAdditional = "")
{
Word.Document objDocument;

try
{
if (clsError.ErrorFlag() == true)
return;

gApplicationWord.StatusBar = "Creating the document from : " + sFolderPath + sFileName + sAdditional + sExtension + " ...";

objDocument = gApplicationWord.Documents.Add(Template: sFolderPath + sFileName + sAdditional + sExtension, NewTemplate: false, DocumentType: Word.WdNewDocumentType.wdNewBlankDocument, Visible: true);

gApplicationWord.StatusBar = "";

NewDocument = objDocument;
}
catch (Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}

finally
{
objDocument = null/* TODO Change to default(_) if this is not a reference type */;

if (gbDEBUG_WORD == true | ((!mobjCOMException == null) | (!mobjException == null)))
{
string serrortext;

if (enNewDocumentType == zBET_enNewDocumentType.FromTemplate)
serrortext = "template";
if (enNewDocumentType == zBET_enNewDocumentType.FromDocument)
serrortext = "document";

clsError.Handle("NewDocument", msCLASSNAME, "create a new document from the " + serrortext + ":" + gsCRLF + "'" + sFolderPath + sFileName + sAdditional + sExtension + "'.", mobjCOMException, mobjException);
}
}
}
Public Shared Function NewDocument(ByVal enNewDocumentType As zBET_enNewDocumentType, _
ByVal sFolderPath As String, _
ByVal sFileName As String, _
Optional ByVal sExtension As String = ".dot", _
Optional ByVal sAdditional As String = "") As _
Word.Document

Dim objDocument As Word.Document

Try
If clsError.ErrorFlag() = True Then Exit Function

gApplicationWord.StatusBar = "Creating the document from : " & _
sFolderPath & sFileName & _
sAdditional & sExtension & " ..."

objDocument = gApplicationWord.Documents.Add( _
Template:=sFolderPath & sFileName & sAdditional & sExtension, _
NewTemplate:=False, _
DocumentType:=Word.WdNewDocumentType.wdNewBlankDocument, _
Visible:=True)

gApplicationWord.StatusBar = ""

NewDocument = objDocument

Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException

Finally
objDocument = Nothing

If gbDEBUG_WORD = True Or _
((Not mobjCOMException Is Nothing) Or (Not mobjException Is Nothing)) Then
Dim serrortext As String

If enNewDocumentType = zBET_enNewDocumentType.FromTemplate Then serrortext = "template"
If enNewDocumentType = zBET_enNewDocumentType.FromDocument Then serrortext = "document"

Call clsError.Handle("NewDocument", msCLASSNAME, _
"create a new document from the " & serrortext & ":" & _
gsCRLF & "'" & sFolderPath & sFileName & sAdditional & sExtension & "'.", _
mobjCOMException, mobjException)
End If
End Try
End Function

Doc_NewDocumentBlank

public static void NewDocumentBlank()
{
try
{
if (clsError.ErrorFlag() == true)
return;

gApplicationWord.StatusBar = "Creating a new document...";

gApplicationWord.Documents.Add(Template: "", NewTemplate: false, DocumentType: Word.WdNewDocumentType.wdNewBlankDocument, Visible: true);

gApplicationWord.StatusBar = "";
}
catch (Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}

finally
{
if (gbDEBUG_WORD == true | ((!mobjCOMException == null) | (!mobjException == null)))
clsError.Handle("NewDocumentBlank", msCLASSNAME, "create a new blank document.", mobjCOMException, mobjException);
}
}
Public Shared Sub NewDocumentBlank()

Try
If clsError.ErrorFlag() = True Then Exit Sub

gApplicationWord.StatusBar = "Creating a new document..."

gApplicationWord.Documents.Add( _
Template:="", _
NewTemplate:=False, _
DocumentType:=Word.WdNewDocumentType.wdNewBlankDocument, _
Visible:=True)

gApplicationWord.StatusBar = ""

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("NewDocumentBlank", msCLASSNAME, _
"create a new blank document.", _
mobjCOMException, mobjException)
End If
End Try
End Sub

Doc_OpenDocument

public static bool OpenDocument(string sFolderPath, string sFileName, string sExtension = ".doc", string sAdditional = "", bool bInformUser = false)
{
try
{
if (clsError.ErrorFlag() == true)
return;

gApplicationWord.StatusBar = "Opening the document : " + sFolderPath + sFileName + sAdditional + sExtension + " ...";

gApplicationWord.Documents.Open(FileName: sFolderPath + sFileName + sAdditional + sExtension);

OpenDocument = true;

gApplicationWord.StatusBar = "";
}
catch (Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}

finally
{
if (gbDEBUG_WORD == true | ((!mobjCOMException == null) | (!mobjException == null)))
clsError.Handle("OpenDocument", msCLASSNAME, "open the following document:" + gsCRLF + "'" + sFolderPath + sFileName + sExtension + "'.", mobjCOMException, mobjException);
}
}
Public Shared Function OpenDocument(ByVal sFolderPath As String, _
ByVal sFileName As String, _
Optional ByVal sExtension As String = ".doc", _
Optional ByVal sAdditional As String = "", _
Optional ByVal bInformUser As Boolean = False) _
As Boolean

Try
If clsError.ErrorFlag() = True Then Exit Function

gApplicationWord.StatusBar = "Opening the document : " & _
sFolderPath & sFileName & _
sAdditional & sExtension & " ..."

gApplicationWord.Documents.Open( _
FileName:=sFolderPath & sFileName & sAdditional & sExtension)

OpenDocument = True

gApplicationWord.StatusBar = ""

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("OpenDocument", msCLASSNAME, _
"open the following document:" & _
gsCRLF & "'" & sFolderPath & sFileName & sExtension & "'.", _
mobjCOMException, mobjException)
End If
End Try
End Function

Doc_PageCount

Returns the number of printed pages in the document, excluding hidden text and revisions.
public int Document_PageCount(ref Word.Document objDocument)
{
Word.View objView;
Word.WdRevisionsView objRevisionsView;
bool bShowRevisionsAndComments;
bool bShowAll;
bool bShowHiddenText;
int iCount = 0;

try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

objView = objDocument.ActiveWindow.View;
// Do not show Revisions or Comments
bShowRevisionsAndComments = objView.ShowRevisionsAndComments;
objView.ShowRevisionsAndComments = false;
// Show Final View
objRevisionsView = objView.RevisionsView;
objView.RevisionsView = Word.WdRevisionsView.wdRevisionsViewFinal;
bShowAll = objView.ShowAll; // Do not show hidden text, Note: must toggle the ShowAll property
bShowHiddenText = objView.ShowHiddenText;

objView.ShowAll = false;
objView.ShowHiddenText = false;

// Note: ComputeStatistics is faster than using the Information object
iCount = objDocument.ComputeStatistics(Word.WdStatistic.wdStatisticPages);

objView.ShowRevisionsAndComments = bShowRevisionsAndComments;
objView.RevisionsView = objRevisionsView;
objView.ShowAll = bShowAll;
objView.ShowHiddenText = bShowHiddenText;

return iCount;
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
}
}
Returns the number of printed pages in the document, excluding hidden text and revisions.
Public Function Document_PageCount(ByRef objDocument As Word.Document) As Integer

Dim objView As Word.View
Dim objRevisionsView As Word.WdRevisionsView
Dim bShowRevisionsAndComments As Boolean
Dim bShowAll As Boolean
Dim bShowHiddenText As Boolean
Dim iCount As Integer = 0

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

objView = objDocument.ActiveWindow.View
' Do not show Revisions or Comments
bShowRevisionsAndComments = objView.ShowRevisionsAndComments
objView.ShowRevisionsAndComments = False
' Show Final View
objRevisionsView = objView.RevisionsView
objView.RevisionsView = Word.WdRevisionsView.wdRevisionsViewFinal
bShowAll = objView.ShowAll ' Do not show hidden text, Note: must toggle the ShowAll property
bShowHiddenText = objView.ShowHiddenText

objView.ShowAll = False
objView.ShowHiddenText = False

' Note: ComputeStatistics is faster than using the Information object
iCount = objDocument.ComputeStatistics(Word.WdStatistic.wdStatisticPages)

objView.ShowRevisionsAndComments = bShowRevisionsAndComments
objView.RevisionsView = objRevisionsView
objView.ShowAll = bShowAll
objView.ShowHiddenText = bShowHiddenText

Return iCount

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

Doc_Save

public bool Doc_Save(ref Word.Document objDocument, bool bForceUserToSave = false)
{
bool bDocumentSaveError;
bool blnSucess = false;

try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

if ((objDocument == null))
objDocument = Document_GetActive();

if (objDocument.Saved == false)
{
if (objDocument.ReadOnly == false)
{
bDocumentSaveError = true;
objDocument.Save();
bDocumentSaveError = false;
blnSucess = true;
}
else
modMessages.Document_CannotBeSavedIsReadOnly();
}
else
blnSucess = true;
}
catch (Exception ex)
{
if ((bDocumentSaveError == false))
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
else if ((bForceUserToSave == true))
{
Document_SaveDocumentBeforeContinuing();
modWordObjectModel.Doc_Save(objDocument, bForceUserToSave);
}
}

return blnSucess;
}
Public Function Doc_Save(ByRef objDocument As Word.Document, _
Optional ByVal bForceUserToSave As Boolean = False) As Boolean

Dim bDocumentSaveError As Boolean
Dim blnSucess As Boolean = False

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

If (objDocument Is Nothing) Then objDocument = Document_GetActive()

If objDocument.Saved = False Then
If objDocument.ReadOnly = False Then
bDocumentSaveError = True
objDocument.Save()
bDocumentSaveError = False
blnSucess = True
Else
Call modMessages.Document_CannotBeSavedIsReadOnly()
End If
Else
blnSucess = True
End If

Catch ex As System.Exception
If (bDocumentSaveError = False) Then
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
Else
If (bForceUserToSave = True) Then
Call Document_SaveDocumentBeforeContinuing()
Call modWordObjectModel.Doc_Save(objDocument, bForceUserToSave)
End If
End If
End Try

Return blnSucess
End Function

Doc_SaveAs

public static bool Doc_SaveAs(string sFolderPath, string sFileName, string sExtension = ".xls", bool bDeleteIfExists = false, bool bInformUser = false, string sAdditional = "")
{
try
{
bool breplace;

if (clsError.ErrorFlag() == true)
return;

SaveAs = false;

if (clsFile.Exists(sFolderPath, sFileName, sExtension, false) == true)
{
if (bInformUser == true)
breplace = clszMessagesGeneral.FileReplaceQuestion(sFolderPath, sFileName);

if (breplace == true)
{
if (bDeleteIfExists == true)
clsFile.Delete(sFolderPath, sFileName, sExtension);

gApplicationWord.ActiveDocument.SaveAs(FileName: sFolderPath + sFileName + sAdditional + sExtension);
SaveAs = true;
}
}
else
{
gApplicationWord.ActiveDocument.SaveAs(FileName: sFolderPath + sFileName + sAdditional + sExtension);
SaveAs = true;
}
}
catch (Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}

finally
{
if (gbDEBUG_WORD == true | ((!mobjCOMException == null) | (!mobjException == null)))
clsError.Handle("SaveAs", msCLASSNAME, "save the file '" + sFileName + sExtension + " '" + "in the following directory:" + gsCRLF + "'" + sFolderPath + "'.", mobjCOMException, mobjException);
}
}
Public Shared Function Doc_SaveAs(ByVal sFolderPath As String, _
ByVal sFileName As String, _
Optional ByVal sExtension As String = ".xls", _
Optional ByVal bDeleteIfExists As Boolean = False, _
Optional ByVal bInformUser As Boolean = False, _
Optional ByVal sAdditional As String = "") As Boolean

Try
Dim breplace As Boolean

If clsError.ErrorFlag() = True Then Exit Function

SaveAs = False

If clsFile.Exists(sFolderPath, sFileName, sExtension, False) = True Then

If bInformUser = True Then
breplace = clszMessagesGeneral.FileReplaceQuestion(sFolderPath, sFileName)
End If

If breplace = True Then
If bDeleteIfExists = True Then
Call clsFile.Delete(sFolderPath, sFileName, sExtension)
End If

gApplicationWord.ActiveDocument.SaveAs(FileName:=sFolderPath & sFileName & _
sAdditional & sExtension)
SaveAs = True
End If
Else
gApplicationWord.ActiveDocument.SaveAs(FileName:=sFolderPath & sFileName & _
sAdditional & sExtension)
SaveAs = True
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("SaveAs", msCLASSNAME, _
"save the file '" & sFileName & sExtension & " '" & _
"in the following directory:" & _
gsCRLF & "'" & sFolderPath & "'.", _
mobjCOMException, mobjException)
End If
End Try
End Function

DocVariable_Add

Adds a custom variable to a document.
public void DocVariable_Add(ref Word.Document objDocument, string sDocVariable, string sDocValue, bool bResetValue = false, bool bInformUser = false)
{
try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

if ((objDocument == null))
objDocument = Document_GetActive();

if (DocVariable_Exists(objDocument, sDocVariable) == false)
objDocument.Variables.Add(sDocVariable, (object)sDocValue);
else if ((bResetValue == true))
objDocument.Variables(sDocVariable).Value = sDocValue;
}
catch (Exception ex)
{
if ((bInformUser == true))
modMessages.DocVariable_UnableToAdd(sDocVariable);
}
}
Adds a custom variable to a document.
Public Sub DocVariable_Add(ByRef objDocument As Word.Document, _
ByVal sDocVariable As String, _
ByVal sDocValue As String, _
Optional ByVal bResetValue As Boolean = False, _
Optional ByVal bInformUser As Boolean = False)

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

If DocVariable_Exists(objDocument, sDocVariable) = False Then
objDocument.Variables.Add(sDocVariable, CType(sDocValue, Object))
Else
If (bResetValue = True) Then
objDocument.Variables(sDocVariable).Value = sDocValue
End If
End If

Catch ex As System.Exception
If (bInformUser = True) Then
Call modMessages.DocVariable_UnableToAdd(sDocVariable)
End If
End Try
End Sub

DocVariable_Delete

Removes a custom variable from the active document.
public void DocVariable_Delete(ref Word.Document objDocument, string sDocVariable, bool bCheckExists = false)
{
Word.Variable ovariable;

try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

if ((objDocument == null))
objDocument = Document_GetActive();

if ((bCheckExists == true))
{
if (modWordObjectModel.DocVariable_Exists(objDocument, sDocVariable) == false)
return;
}

ovariable = objDocument.Variables(sDocVariable);
ovariable.Delete();
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
}
}
Removes a custom variable from the active document.
Public Sub DocVariable_Delete(ByRef objDocument As Word.Document, _
ByVal sDocVariable As String, _
Optional ByVal bCheckExists As Boolean = False)

Dim ovariable As Word.Variable

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

If (bCheckExists = True) Then
If modWordObjectModel.DocVariable_Exists(objDocument, sDocVariable) = False Then Exit Sub
End If

ovariable = objDocument.Variables(sDocVariable)
ovariable.Delete()

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

DocVariable_Exists

public bool VariableExists(ref Word.Document objDocument, string sDocVariable, bool bInformUser = false)
{
Word.Variable oVariable;
string strValue;

try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

if ((objDocument == null))
objDocument = Document_GetActive();

oVariable = objDocument.Variables(sDocVariable);
strValue = oVariable.Name;

// Call Tracer_Add2("VARIABLE", "The document variable '" & sDocVariable & "' exists")
return true;
}
catch (Exception ex)
{
return false;
Tracer_Add2("VARIABLE", "The document variable '" + sDocVariable + "' does not exist");
if ((bInformUser == true))
modMessages.DocVariable_DoesNotExist(sDocVariable);
}
}
Public Function VariableExists(ByRef objDocument As Word.Document, _
ByVal sDocVariable As String, _
Optional ByVal bInformUser As Boolean = False) As Boolean

Dim oVariable As Word.Variable
Dim strValue As String

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

If (objDocument Is Nothing) Then objDocument = Document_GetActive()

oVariable = objDocument.Variables(sDocVariable)
strValue = oVariable.Name

'Call Tracer_Add2("VARIABLE", "The document variable '" & sDocVariable & "' exists")
Return True

Catch ex As System.Exception
Return False
Call Tracer_Add2("VARIABLE", "The document variable '" & sDocVariable & "' does not exist")
If (bInformUser = True) Then
Call modMessages.DocVariable_DoesNotExist(sDocVariable)
End If
End Try

End Function

DocVariable_Get

Returns the value of a custom variable in the active document.
public string DocVariable_Get(ref Word.Document objDocument, string sDocVariable, bool bCheckExists = true, bool bInformUser = false, bool bCheckMultiples = false, int iFirstNumber = 1, string sDifferentDefault = "")
{
string sTempVarName;
string sConcatenated = "";
int intCounter;

try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
{
return sDifferentDefault; return;
}

DocVariable_Get = sDifferentDefault;

if ((objDocument == null))
objDocument = Document_GetActive();

if (bCheckMultiples == false)
{
if (bCheckExists == false)
return objDocument.Variables(sDocVariable).Value;
else if (DocVariable_Exists(objDocument, sDocVariable) == true)
return objDocument.Variables(sDocVariable).Value;
else
{
Tracer_Add2("VARIABLE", "'" + sDocVariable + "' doesn't exist", true, System.Reflection.MethodBase.GetCurrentMethod());

if ((bInformUser == true))
modMessages.Message_General_DocVariableNotCreated(sDocVariable);
}
}
else if (modWordObjectModel.DocVariable_MultiplesExist(objDocument, sDocVariable) == true)
{
intCounter = iFirstNumber;
sTempVarName = sDocVariable + System.Convert.ToHexString(intCounter);

while (!modWordObjectModel.DocVariable_Exists(objDocument, sTempVarName) == false)
{
sConcatenated = sConcatenated + objDocument.Variables(sTempVarName).Value;

intCounter = intCounter + 1;
sTempVarName = sDocVariable + System.Convert.ToHexString(intCounter);
}
return sConcatenated.Trim();
}
else
return objDocument.Variables(sDocVariable).Value;
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
return "";
}
}
Returns the value of a custom variable in the active document.
Public Function DocVariable_Get(ByRef objDocument As Word.Document, _
ByVal sDocVariable As String, _
Optional ByVal bCheckExists As Boolean = True, _
Optional ByVal bInformUser As Boolean = False, _
Optional ByVal bCheckMultiples As Boolean = False, _
Optional ByVal iFirstNumber As Integer = 1, _
Optional ByVal sDifferentDefault As String = "") As String

Dim sTempVarName As String
Dim sConcatenated As String = ""
Dim intCounter As Integer

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

DocVariable_Get = sDifferentDefault

If (objDocument Is Nothing) Then objDocument = Document_GetActive()

If bCheckMultiples = False Then
If bCheckExists = False Then
Return objDocument.Variables(sDocVariable).Value
Else
If DocVariable_Exists(objDocument, sDocVariable) = True Then
Return objDocument.Variables(sDocVariable).Value
Else
Call Tracer_Add2("VARIABLE", "'" & sDocVariable & "' doesn't exist", _
True, System.Reflection.MethodBase.GetCurrentMethod)

If (bInformUser = True) Then
modMessages.Message_General_DocVariableNotCreated(sDocVariable)
End If
End If
End If

Else
If modWordObjectModel.DocVariable_MultiplesExist(objDocument, sDocVariable) = True Then

intCounter = iFirstNumber
sTempVarName = sDocVariable & CStr(intCounter)

Do Until modWordObjectModel.DocVariable_Exists(objDocument, sTempVarName) = False
sConcatenated = sConcatenated & objDocument.Variables(sTempVarName).Value

intCounter = intCounter + 1
sTempVarName = sDocVariable & CStr(intCounter)
Loop
Return sConcatenated.Trim
Else
Return objDocument.Variables(sDocVariable).Value
End If
End If

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

DocVariable_GetBoolean

public bool DocVariable_GetBoolean(ref Word.Document objDocument, string sDocVariable, bool bCheckExists = true, bool bInformUser = false)
{

// returns False if the document variable does not exist
string svariable;

try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

if ((objDocument == null))
objDocument = Document_GetActive();

if (modWordObjectModel.DocVariable_Exists(objDocument, sDocVariable) == true)
{
svariable = modWordObjectModel.DocVariable_Get(objDocument, sDocVariable, false);
if (svariable.Trim().ToUpper() == "TRUE" | svariable.Trim().ToUpper() == "FALSE")
return System.Convert.ToBoolean(svariable.Trim());
}
else
{
Tracer_Add2("VARIABLE", sDocVariable + "' doesn't exist", true, System.Reflection.MethodBase.GetCurrentMethod());

if (bInformUser == true)
modMessages.Message_General_DocVariableNotCreated(sDocVariable);
return false;
}
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
}
}
Public Function DocVariable_GetBoolean(ByRef objDocument As Word.Document, _
ByVal sDocVariable As String, _
Optional ByVal bCheckExists As Boolean = True, _
Optional ByVal bInformUser As Boolean = False) As Boolean

'returns False if the document variable does not exist
Dim svariable As String

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

If (objDocument Is Nothing) Then objDocument = Document_GetActive()

If modWordObjectModel.DocVariable_Exists(objDocument, sDocVariable) = True Then
svariable = modWordObjectModel.DocVariable_Get(objDocument, sDocVariable, False)
If svariable.Trim.ToUpper = "TRUE" Or svariable.Trim.ToUpper = "FALSE" Then
Return CType(svariable.Trim, Boolean)
End If
Else
Call Tracer_Add2("VARIABLE", sDocVariable & "' doesn't exist", _
True, System.Reflection.MethodBase.GetCurrentMethod)

If bInformUser = True Then
modMessages.Message_General_DocVariableNotCreated(sDocVariable)
End If
Return False
End If

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

DocVariable_GetInteger

public int DocVariable_GetInteger(ref Word.Document objDocument, string sDocVariable, bool bCheckExists = true, bool bInformUser = false)
{
// returns -1 if the document variable does not exist
string svariable;

try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

if ((objDocument == null))
objDocument = Document_GetActive();

if (modWordObjectModel.DocVariable_Exists(objDocument, sDocVariable) == true)
{
svariable = modWordObjectModel.DocVariable_Get(objDocument, sDocVariable, false);
if ((svariable.Trim().Length > 0))
return System.Convert.ToInt32(svariable.Trim());
else
return -1;
}
else
{
Tracer_Add2("VARIABLE", "The document variable '" + sDocVariable + "' does not exist", true, System.Reflection.MethodBase.GetCurrentMethod());

if (bInformUser == true)
modMessages.Message_General_DocVariableNotCreated(sDocVariable);
return -1;
}
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
}
}
Public Function DocVariable_GetInteger(ByRef objDocument As Word.Document, _
ByVal sDocVariable As String, _
Optional ByVal bCheckExists As Boolean = True, _
Optional ByVal bInformUser As Boolean = False) As Integer
'returns -1 if the document variable does not exist
Dim svariable As String

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

If (objDocument Is Nothing) Then objDocument = Document_GetActive()

If modWordObjectModel.DocVariable_Exists(objDocument, sDocVariable) = True Then
svariable = modWordObjectModel.DocVariable_Get(objDocument, sDocVariable, False)
If (svariable.Trim.Length > 0) Then
Return CType(svariable.Trim, Integer)
Else
Return -1
End If
Else
Call Tracer_Add2("VARIABLE", "The document variable '" & sDocVariable & "' does not exist", _
True, System.Reflection.MethodBase.GetCurrentMethod)

If bInformUser = True Then
modMessages.Message_General_DocVariableNotCreated(sDocVariable)
End If
Return -1
End If

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

DocVariable_GetLong

public long DocVariable_GetLong(ref Word.Document objDocument, string sDocVariable, bool bCheckExists = true, bool bInformUser = false)
{

// returns -1 if the document variable does not exist
string svariable;

try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

if ((objDocument == null))
objDocument = Document_GetActive();

if (modWordObjectModel.DocVariable_Exists(objDocument, sDocVariable) == true)
{
svariable = modWordObjectModel.DocVariable_Get(objDocument, sDocVariable, false);
if ((svariable.Trim().Length > 0))
return System.Convert.ToInt64(svariable.Trim());
else
return -1;
}
else
{
Tracer_Add2("VARIABLE", sDocVariable + "' doesn't exist", true, System.Reflection.MethodBase.GetCurrentMethod());

if (bInformUser == true)
modMessages.Message_General_DocVariableNotCreated(sDocVariable);
return -1;
}
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
}
}
Public Function DocVariable_GetLong(ByRef objDocument As Word.Document, _
ByVal sDocVariable As String, _
Optional ByVal bCheckExists As Boolean = True, _
Optional ByVal bInformUser As Boolean = False) As Long

'returns -1 if the document variable does not exist
Dim svariable As String

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

If (objDocument Is Nothing) Then objDocument = Document_GetActive()

If modWordObjectModel.DocVariable_Exists(objDocument, sDocVariable) = True Then
svariable = modWordObjectModel.DocVariable_Get(objDocument, sDocVariable, False)
If (svariable.Trim.Length > 0) Then
Return CType(svariable.Trim, Long)
Else
Return -1
End If
Else
Call Tracer_Add2("VARIABLE", sDocVariable & "' doesn't exist", _
True, System.Reflection.MethodBase.GetCurrentMethod)

If bInformUser = True Then
modMessages.Message_General_DocVariableNotCreated(sDocVariable)
End If
Return -1
End If

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

DocVariable_MultiplesDelete

public bool DocVariable_MultiplesDelete(ref Word.Document objDocument, string sDocVariable, bool bStartAtZero = false)
{
string stempvariable;
int icounter;
Word.Variable ovariable;

try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

if ((objDocument == null))
objDocument = Document_GetActive();

if ((bStartAtZero == true))
icounter = 0;
else
icounter = 1;

stempvariable = sDocVariable + System.Convert.ToHexString(icounter);

while (!modWordObjectModel.DocVariable_Exists(objDocument, stempvariable) == false)
{
ovariable = objDocument.Variables(stempvariable);
ovariable.Delete();
icounter = icounter + 1;

stempvariable = sDocVariable + System.Convert.ToHexString(icounter);
}
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
}
}
Public Function DocVariable_MultiplesDelete(ByRef objDocument As Word.Document, _
ByVal sDocVariable As String, _
Optional ByVal bStartAtZero As Boolean = False) As Boolean

Dim stempvariable As String
Dim icounter As Integer
Dim ovariable As Word.Variable

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

If (objDocument Is Nothing) Then objDocument = Document_GetActive()

If (bStartAtZero = True) Then
icounter = 0
Else
icounter = 1
End If

stempvariable = sDocVariable & CStr(icounter)

Do Until modWordObjectModel.DocVariable_Exists(objDocument, stempvariable) = False
ovariable = objDocument.Variables(stempvariable)
ovariable.Delete()
icounter = icounter + 1

stempvariable = sDocVariable & CStr(icounter)
'Return True
Loop

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

DocVariable_MultiplesExist

public bool DocVariable_MultiplesExist(ref Word.Document objDocument, string sDocVariable)
{
try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

if ((objDocument == null))
objDocument = Document_GetActive();

if (modWordObjectModel.DocVariable_Exists(objDocument, sDocVariable) == true)
return false;
else
{
sDocVariable = sDocVariable + "1";
if (objDocument.Variables(sDocVariable).Value.Length > 0)
return true;
if (objDocument.Variables(sDocVariable).Value.Length == 0)
return false;
}
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
}
}
Public Function DocVariable_MultiplesExist(ByRef objDocument As Word.Document, _
ByVal sDocVariable As String) As Boolean

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

If (objDocument Is Nothing) Then objDocument = Document_GetActive()

If modWordObjectModel.DocVariable_Exists(objDocument, sDocVariable) = True Then
Return False
Else
sDocVariable = sDocVariable & "1"
If objDocument.Variables(sDocVariable).Value.Length > 0 Then Return True
If objDocument.Variables(sDocVariable).Value.Length = 0 Then Return False
End If

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

DocVariable_Save

public bool DocVariable_Save(ref Word.Document objDocument, string sDocVariable, string sDocValue, bool bCheckMultiples = true, bool bStartAtZero = false)
{
int intVars = 0;
int iSegmentLength = 65200;
bool blnCompleted = false;

try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

if ((objDocument == null))
objDocument = Document_GetActive();

if ((bCheckMultiples == true))
modWordObjectModel.DocVariable_MultiplesDelete(objDocument, sDocVariable, bStartAtZero);

if (sDocValue == null)
sDocValue = " ";


' If (sDocValue <> " ") And Not (sDocVariable Like "strHTML%") Then
' Call Tracer_Add2("VARIABLE", "The document variable '" & sDocVariable & "' is attempting to save: " & _
' "'" & sDocValue & "'")
' End If

if (sDocValue.Length > iSegmentLength)
{
intVars = (sDocValue.Length / iSegmentLength);
if (sDocValue.Length % iSegmentLength > 0)
intVars = intVars + 1;
}

if (intVars > 0)
{
int iStart;
long intCutoff;
object[] allStrings = new object[intVars - 1 + 1];

iStart = 1;
intCutoff = iSegmentLength;

for (int i = 0; i <= intVars - 1; i++)
{
var oldAllStrings = allStrings;
allStrings = new object[i + 1];
if (oldAllStrings != null)
Array.Copy(oldAllStrings, allStrings, Math.Min(i + 1, oldAllStrings.Length));
allStrings[i] = Microsoft.VisualBasic.Mid(sDocValue, iStart, iSegmentLength);
iStart = iStart + iSegmentLength;
}

if (allStrings.Length > 0)
{
for (int i = 1; i <= allStrings.Length; i++)
{
objDocument.Variables.Add(sDocVariable + System.Convert.ToHexString(i), allStrings[i - 1]);
blnCompleted = true;

modSpecific.SaveHTMLLevels(objDocument, sDocVariable, System.Convert.ToHexString(i));
}
}
else
modSpecific.SaveHTMLLevels(objDocument, sDocVariable, System.Convert.ToHexString(0));
}

if (blnCompleted == false)
{
if (sDocVariable == "")
sDocVariable = " ";

if (modWordObjectModel.DocVariable_Exists(objDocument, sDocVariable))
{
objDocument.Variables(sDocVariable).Value = sDocValue;

// This is only being used while Addin is active!
if (Microsoft.VisualBasic.Left(sDocVariable, 13) == "strWebSummary")
{
if (modWordObjectModel.DocVariable_Exists(objDocument, "strWebSummary2"))
objDocument.Variables("strWebSummary2").Value = " ";

if (modWordObjectModel.DocVariable_Exists(objDocument, "strWebSummary3"))
objDocument.Variables("strWebSummary3").Value = " ";
}
}
else
objDocument.Variables.Add(sDocVariable, (object)sDocValue);

return true;
blnCompleted = true;
}

return blnCompleted;
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
}
finally
{
' If (sDocValue <> " ") And Not (sDocVariable Like "strHTML%") Then
' Call Tracer_Add2("VARIABLE", "The document variable '" & sDocVariable & "' has been saved.")
' End If

}
}
Public Function DocVariable_Save(ByRef objDocument As Word.Document, _
ByVal sDocVariable As String, _
ByVal sDocValue As String, _
Optional ByVal bCheckMultiples As Boolean = True, _
Optional ByVal bStartAtZero As Boolean = False) As Boolean

Dim intVars As Integer = 0
Dim iSegmentLength As Integer = 65200
Dim blnCompleted As Boolean = False

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

If (objDocument Is Nothing) Then objDocument = Document_GetActive()

If (bCheckMultiples = True) Then
Call modWordObjectModel.DocVariable_MultiplesDelete(objDocument, sDocVariable, bStartAtZero)
End If

If sDocValue Is Nothing Then
sDocValue = " "
End If

If (sDocValue <> " ") And Not (sDocVariable Like "strHTML%") Then
Call Tracer_Add2("VARIABLE", "The document variable '" & sDocVariable & "' is attempting to save: " & _
"'" & sDocValue & "'")
End If

If sDocValue.Length > iSegmentLength Then
intVars = (sDocValue.Length \ iSegmentLength)
If sDocValue.Length Mod iSegmentLength > 0 Then intVars = intVars + 1
End If

If intVars > 0 Then

Dim iStart As Integer
Dim intCutoff As Long
Dim allStrings(intVars - 1) As Object

iStart = 1
intCutoff = iSegmentLength

For i As Integer = 0 To intVars - 1
ReDim Preserve allStrings(i)
allStrings(i) = Microsoft.VisualBasic.Mid(sDocValue, iStart, iSegmentLength)
iStart = iStart + iSegmentLength
Next i

If allStrings.Length > 0 Then
For i As Integer = 1 To allStrings.Length
objDocument.Variables.Add(sDocVariable & CStr(i), allStrings(i - 1))
blnCompleted = True

Call modSpecific.SaveHTMLLevels(objDocument, sDocVariable, CStr(i))
Next i
Else

Call modSpecific.SaveHTMLLevels(objDocument, sDocVariable, CStr(0))
End If
End If

If blnCompleted = False Then
If sDocVariable = "" Then sDocVariable = " "

If modWordObjectModel.DocVariable_Exists(objDocument, sDocVariable) Then
objDocument.Variables(sDocVariable).Value = sDocValue

'This is only being used while FID Addin is active!
If Microsoft.VisualBasic.Left(sDocVariable, 13) = "strWebSummary" Then
If modWordObjectModel.DocVariable_Exists(objDocument, "strWebSummary2") Then
objDocument.Variables("strWebSummary2").Value = " "
End If
If modWordObjectModel.DocVariable_Exists(objDocument, "strWebSummary3") Then
objDocument.Variables("strWebSummary3").Value = " "
End If
End If
Else
objDocument.Variables.Add(sDocVariable, CType(sDocValue, Object))
End If

Return True
blnCompleted = True
End If

Return blnCompleted

Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
Finally
If (sDocValue <> " ") And Not (sDocVariable Like "strHTML%") Then
Call Tracer_Add2("VARIABLE", "The document variable '" & sDocVariable & "' has been saved.")
End If
End Try
End Function

Find_StringMakeBold

public void Find_StringMakeBold(Word.Range objRange, string findString)
{
try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

// removes the bold formatting from everything between the tags
{
var withBlock = objRange.Find;
withBlock.ClearFormatting();
withBlock.MatchWildcards = true;
withBlock.Format = false;
withBlock.Wrap = Word.WdFindWrap.wdFindContinue;
withBlock.Forward = true;
withBlock.Text = findString;
withBlock.MatchCase = false;

withBlock.Replacement.ClearFormatting();
withBlock.Replacement.Font.Bold = -1; // True
withBlock.Execute(Replace: Word.WdReplace.wdReplaceAll);
}

// removes the bold tags (open and close)
if (findString.IndexOf(@"\") > -1)
{
{
var withBlock = objRange.Find;
withBlock.Format = false;
withBlock.Wrap = Word.WdFindWrap.wdFindContinue;
withBlock.Forward = true;
withBlock.Text = @"\";
withBlock.MatchCase = false;
withBlock.Replacement.Text = "";
withBlock.Execute(Replace: Word.WdReplace.wdReplaceAll);
}
{
var withBlock = objRange.Find;
withBlock.Format = false;
withBlock.Wrap = Word.WdFindWrap.wdFindContinue;
withBlock.Forward = true;
withBlock.Text = @"\<\/b\>";
withBlock.MatchCase = false;
withBlock.Replacement.Text = "";
withBlock.Execute(Replace: Word.WdReplace.wdReplaceAll);
}
}
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
}
}
Public Sub Find_StringMakeBold(ByVal objRange As Word.Range, _
ByVal findString As String)

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

'removes the bold formatting from everything between the tags
With objRange.Find
.ClearFormatting()
.MatchWildcards = True
.Format = False
.Wrap = Word.WdFindWrap.wdFindContinue
.Forward = True
.Text = findString
.MatchCase = False

.Replacement.ClearFormatting()
.Replacement.Font.Bold = -1 'True
.Execute(Replace:=Word.WdReplace.wdReplaceAll)
End With

'removes the bold tags (open and close)
If findString.IndexOf("\") > -1 Then
With objRange.Find
.Format = False
.Wrap = Word.WdFindWrap.wdFindContinue
.Forward = True
.Text = "\"
.MatchCase = False
.Replacement.Text = ""
.Execute(Replace:=Word.WdReplace.wdReplaceAll)
End With
With objRange.Find
.Format = False
.Wrap = Word.WdFindWrap.wdFindContinue
.Forward = True
.Text = "\<\/b\>"
.MatchCase = False
.Replacement.Text = ""
.Execute(Replace:=Word.WdReplace.wdReplaceAll)
End With
End If

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

Find_StringMakeItalic

public void Find_StringMakeItalic(Word.Range objRange, string findString)
{
try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

// removes the bold formatting from everything between the tags
{
var withBlock = objRange.Find;
withBlock.ClearFormatting();
withBlock.MatchWildcards = true;
withBlock.Format = false;
withBlock.Wrap = Word.WdFindWrap.wdFindContinue;
withBlock.Forward = true;
withBlock.Text = findString;
withBlock.MatchCase = false;

withBlock.Replacement.ClearFormatting();
withBlock.Replacement.Font.Italic = -1; // True
withBlock.Execute(Replace: Word.WdReplace.wdReplaceAll);
}

// removes the bold tags (open and close)
if (findString.IndexOf(@"\") > -1)
{
{
var withBlock = objRange.Find;
withBlock.Format = false;
withBlock.Wrap = Word.WdFindWrap.wdFindContinue;
withBlock.Forward = true;
withBlock.Text = @"\";
withBlock.MatchCase = false;
withBlock.Replacement.Text = "";
withBlock.Execute(Replace: Word.WdReplace.wdReplaceAll);
}
{
var withBlock = objRange.Find;
withBlock.Format = false;
withBlock.Wrap = Word.WdFindWrap.wdFindContinue;
withBlock.Forward = true;
withBlock.Text = @"\<\/i\>";
withBlock.MatchCase = false;
withBlock.Replacement.Text = "";
withBlock.Execute(Replace: Word.WdReplace.wdReplaceAll);
}
}
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
}
}
Public Sub Find_StringMakeItalic(ByVal objRange As Word.Range, _
ByVal findString As String)

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

'removes the bold formatting from everything between the tags
With objRange.Find
.ClearFormatting()
.MatchWildcards = True
.Format = False
.Wrap = Word.WdFindWrap.wdFindContinue
.Forward = True
.Text = findString
.MatchCase = False

.Replacement.ClearFormatting()
.Replacement.Font.Italic = -1 'True
.Execute(Replace:=Word.WdReplace.wdReplaceAll)
End With

'removes the bold tags (open and close)
If findString.IndexOf("\") > -1 Then
With objRange.Find
.Format = False
.Wrap = Word.WdFindWrap.wdFindContinue
.Forward = True
.Text = "\"
.MatchCase = False
.Replacement.Text = ""
.Execute(Replace:=Word.WdReplace.wdReplaceAll)
End With
With objRange.Find
.Format = False
.Wrap = Word.WdFindWrap.wdFindContinue
.Forward = True
.Text = "\<\/i\>"
.MatchCase = False
.Replacement.Text = ""
.Execute(Replace:=Word.WdReplace.wdReplaceAll)
End With
End If

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

Find_StringMakeSuper

public void Find_StringMakeSuper(Word.Range objRange, string findString)
{
try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

{
var withBlock = objRange.Find;
withBlock.ClearFormatting();
withBlock.MatchWildcards = true;
withBlock.Format = false;
withBlock.Wrap = Word.WdFindWrap.wdFindContinue;
withBlock.Forward = true;
withBlock.Text = findString;
withBlock.MatchCase = false;

withBlock.Replacement.ClearFormatting();
withBlock.Replacement.Font.Superscript = -1; // True
withBlock.Execute(Replace: Word.WdReplace.wdReplaceAll);
}

if (findString.IndexOf(@"\") > -1)
{
{
var withBlock = objRange.Find;
withBlock.Format = false;
withBlock.Wrap = Word.WdFindWrap.wdFindContinue;
withBlock.Forward = true;
withBlock.Text = @"\";
withBlock.MatchCase = false;
withBlock.Replacement.Text = "";
withBlock.Execute(Replace: Word.WdReplace.wdReplaceAll);
}
{
var withBlock = objRange.Find;
withBlock.Format = false;
withBlock.Wrap = Word.WdFindWrap.wdFindContinue;
withBlock.Forward = true;
withBlock.Text = @"\<\/sup\>";
withBlock.MatchCase = false;
withBlock.Replacement.Text = "";
withBlock.Execute(Replace: Word.WdReplace.wdReplaceAll);
}
}
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
}
}
Public Sub Find_StringMakeSuper(ByVal objRange As Word.Range, _
ByVal findString As String)

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

With objRange.Find
.ClearFormatting()
.MatchWildcards = True
.Format = False
.Wrap = Word.WdFindWrap.wdFindContinue
.Forward = True
.Text = findString
.MatchCase = False

.Replacement.ClearFormatting()
.Replacement.Font.Superscript = -1 'True
.Execute(Replace:=Word.WdReplace.wdReplaceAll)
End With

If findString.IndexOf("\") > -1 Then
With objRange.Find
.Format = False
.Wrap = Word.WdFindWrap.wdFindContinue
.Forward = True
.Text = "\"
.MatchCase = False
.Replacement.Text = ""
.Execute(Replace:=Word.WdReplace.wdReplaceAll)
End With
With objRange.Find
.Format = False
.Wrap = Word.WdFindWrap.wdFindContinue
.Forward = True
.Text = "\<\/sup\>"
.MatchCase = False
.Replacement.Text = ""
.Execute(Replace:=Word.WdReplace.wdReplaceAll)
End With
End If

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

FindReplace_RemoveLinkTags

public void FindRemoveLinkTags(Word.Range objRange)
{
try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

{
var withBlock = objRange.Find;
withBlock.ClearFormatting();
withBlock.MatchWildcards = true;
withBlock.Format = false;
withBlock.Wrap = Word.WdFindWrap.wdFindContinue;
withBlock.Forward = true;
withBlock.Text = @"\";
withBlock.MatchCase = true;
{
var withBlock1 = withBlock.Replacement;
withBlock1.ClearFormatting();
withBlock1.Text = "";
}
withBlock.Execute(Replace: Word.WdReplace.wdReplaceAll);
}

{
var withBlock = objRange.Find;
withBlock.ClearFormatting();
withBlock.MatchWildcards = true;
withBlock.Format = false;
withBlock.Wrap = Word.WdFindWrap.wdFindContinue;
withBlock.Forward = true;
withBlock.Text = @"\<\/link\>";
withBlock.MatchCase = true;
{
var withBlock1 = withBlock.Replacement;
withBlock1.ClearFormatting();
withBlock1.Text = "";
}
withBlock.Execute(Replace: Word.WdReplace.wdReplaceAll);
}
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
}
finally
{
objRange = null/* TODO Change to default(_) if this is not a reference type */;
}
}
Public Sub FindRemoveLinkTags(ByVal objRange As Word.Range)
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Sub

With objRange.Find
.ClearFormatting()
.MatchWildcards = True
.Format = False
.Wrap = Word.WdFindWrap.wdFindContinue
.Forward = True
.Text = "\"
.MatchCase = True
With .Replacement
.ClearFormatting()
.Text = ""
End With
.Execute(Replace:=Word.WdReplace.wdReplaceAll)
End With

With objRange.Find
.ClearFormatting()
.MatchWildcards = True
.Format = False
.Wrap = Word.WdFindWrap.wdFindContinue
.Forward = True
.Text = "\<\/link\>"
.MatchCase = True
With .Replacement
.ClearFormatting()
.Text = ""
End With
.Execute(Replace:=Word.WdReplace.wdReplaceAll)
End With

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

IsReading

public bool View_IsReading(bool bInformUser = true)
{
try
{
if (My.Settings.ERROR_OCCURRED == true)
return;

if ((gApplicationWord.ActiveWindow.View.ReadingLayout) == true)
{
if ((bInformUser == true))
modMessages.View_IsReading();
return false;
}
else
return true;
}
catch (Exception ex)
{
modMessages.ErrorMessage(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex, "", false);
}
}
Public Function View_IsReading(Optional ByVal bInformUser As Boolean = True) As Boolean
Try
If My.Settings.ERROR_OCCURRED = True Then Exit Function

If (gApplicationWord.ActiveWindow.View.ReadingLayout) = True Then

If (bInformUser = True) Then
Call modMessages.View_IsReading()
End If
Return False
Else
Return True
End If

Catch ex As Exception
Call modMessages.ErrorMessage(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex, _
"", False)
End Try
End Function

Message_ActivateUnsuccessful

public void Document_ActivateUnsuccessful()
{
System.Windows.Forms.MessageBox.Show("The document that you were working on has been closed or renamed." + System.Environment.NewLine + System.Environment.NewLine + "You will have to close and reopen this dialog box.", My.Settings.APP_WINFORMS_TITLE, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
}
Public Sub Document_ActivateUnsuccessful()
System.Windows.Forms.MessageBox.Show( _
"The document that you were working on has been closed or renamed." & _
System.Environment.NewLine & _
System.Environment.NewLine & _
"You will have to close and reopen this dialog box.", _
My.Settings.APP_WINFORMS_TITLE, _
System.Windows.Forms.MessageBoxButtons.OK, _
System.Windows.Forms.MessageBoxIcon.Exclamation)
End Sub

Message_DocProperty_DoesNotExist

public void DocProperty_DoesNotExist(string sPropertyName)
{
System.Windows.Forms.MessageBox.Show("The document property '" + sPropertyName + "' does not exist.", My.Settings.APP_WINFORMS_TITLE, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
}
Public Sub DocProperty_DoesNotExist(ByVal sPropertyName As String)
System.Windows.Forms.MessageBox.Show( _
"The document property '" & sPropertyName & "' does not exist.", _
My.Settings.APP_WINFORMS_TITLE, _
System.Windows.Forms.MessageBoxButtons.OK, _
System.Windows.Forms.MessageBoxIcon.Information)
End Sub

Message_DocProperty_UnableToAddDocumentIsProtected

public void DocProperty_UnableToAddDocumentIsProtected(string sPropertyName)
{
System.Windows.Forms.MessageBox.Show("Unable to create the document property '" + sPropertyName + "' because the document is protected.", My.Settings.APP_WINFORMS_TITLE, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
}
Public Sub DocProperty_UnableToAddDocumentIsProtected(ByVal sPropertyName As String)
System.Windows.Forms.MessageBox.Show( _
"Unable to create the document property '" & sPropertyName & "' because the document is protected.", _
My.Settings.APP_WINFORMS_TITLE, _
System.Windows.Forms.MessageBoxButtons.OK, _
System.Windows.Forms.MessageBoxIcon.Information)
End Sub

Message_DocVariable_Deleted

public void DocVariable_Deleted(string sDocVariable)
{
string smessage = "";

smessage = "The document variable '" + sDocVariable + "' 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 + ")";

Tracer_Add2("MESSAGE", smessage.Replace(System.Environment.NewLine, " ").Replace(" ", " "));
}
Public Sub DocVariable_Deleted(ByVal sDocVariable As String)

Dim smessage As String = ""

smessage = "The document variable '" & sDocVariable & "' 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

Message_DocVariable_DoesNotExist

public void DocVariable_DoesNotExist(string sDocVariable)
{
System.Windows.Forms.MessageBox.Show("The document variable '" + sDocVariable + "' does not exist.", My.Settings.APP_WINFORMS_TITLE, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
}
Public Sub DocVariable_DoesNotExist(ByVal sDocVariable As String)
System.Windows.Forms.MessageBox.Show( _
"The document variable '" & sDocVariable & "' does not exist.", _
My.Settings.APP_WINFORMS_TITLE, _
System.Windows.Forms.MessageBoxButtons.OK, _
System.Windows.Forms.MessageBoxIcon.Information)
End Sub

Message_DocVariable_UnableToAdd

public void DocVariable_UnableToAdd(string sDocVariable)
{
System.Windows.Forms.MessageBox.Show("Unable to create the document variable '" + sDocVariable + "'.", My.Settings.APP_WINFORMS_TITLE, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
}
Public Sub DocVariable_UnableToAdd(ByVal sDocVariable As String)
System.Windows.Forms.MessageBox.Show( _
"Unable to create the document variable '" & sDocVariable & "'.", _
My.Settings.APP_WINFORMS_TITLE, _
System.Windows.Forms.MessageBoxButtons.OK, _
System.Windows.Forms.MessageBoxIcon.Information)
End Sub

Message_HasNotBeenSaved

public void Document_HasNotBeenSaved()
{
System.Windows.Forms.MessageBox.Show("This document has not been saved." + System.Environment.NewLine + System.Environment.NewLine + "You need to save the file first.", My.Settings.APP_WINFORMS_TITLE, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
}
Public Sub Document_HasNotBeenSaved()
System.Windows.Forms.MessageBox.Show( _
"This document has not been saved." & _
System.Environment.NewLine & _
System.Environment.NewLine & _
"You need to save the file first.", _
My.Settings.APP_WINFORMS_TITLE, _
System.Windows.Forms.MessageBoxButtons.OK, _
System.Windows.Forms.MessageBoxIcon.Information)
End Sub

Property_BuiltInCount

class SurroundingClass
{
public static int DocumentPropertyBuiltInCount(string sDocumentName)
{
try
{
if (clsError.ErrorFlag() == true)
return;

int ipropertycount;
string sitemname;

DocumentPropertyBuiltInCount = gApplicationWord.Documents(sDocumentName).BuiltInDocumentProperties.Count;
}
catch (Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}

finally
{
if (gbDEBUG_WORD == true | ((!mobjCOMException == null) | (!mobjException == null)))
clsError.Handle("DocumentPropertyBuiltInCount", msCLASSNAME, "return the total number of 'built-in' document properties.", mobjCOMException, mobjException);
}
}


public static int PropertyBuiltInCount(string sDocumentName = "")
{
try
{
if (clsError.ErrorFlag() == true)
return;

// Dim objDocumentProperties As Office.DocumentProperties
// objDocumentProperties = _
// CType(gApplicationPowerPoint.Presentations(sPresentationName).BuiltInDocumentProperties, _
// Office.DocumentProperties)
// PropertyBuiltInCount = objDocumentProperties.Count

if (sDocumentName == "")
sDocumentName = gApplicationWord.ActiveDocument.Name;

PropertyBuiltInCount = clszWorkAround.DocumentPropertyBuiltInCount(sDocumentName);
}
catch (Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}

finally
{
if (gbDEBUG_WORD == true | ((IsNothing(mobjCOMException) == false | IsNothing(mobjException) == false)))
clsError.Handle("PropertyBuiltInCount", "clsDocument", "return the number of 'built-in' document properties.", mobjCOMException, mobjException);
}
}
}
Public Shared Function DocumentPropertyBuiltInCount(ByVal sDocumentName As String) _
As Integer

Try
If clsError.ErrorFlag() = True Then Exit Function

Dim ipropertycount As Integer
Dim sitemname As String

DocumentPropertyBuiltInCount = _
gApplicationWord.Documents(sDocumentName).BuiltInDocumentProperties.Count

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("DocumentPropertyBuiltInCount", msCLASSNAME, _
"return the total number of 'built-in' document properties.", _
mobjCOMException, mobjException)
End If
End Try
End Function


Public Shared Function PropertyBuiltInCount(Optional ByVal sDocumentName As String = "") _
As Integer

Try
If clsError.ErrorFlag() = True Then Exit Function

'Dim objDocumentProperties As Office.DocumentProperties
'objDocumentProperties = _
' CType(gApplicationPowerPoint.Presentations(sPresentationName).BuiltInDocumentProperties, _
' Office.DocumentProperties)
'PropertyBuiltInCount = objDocumentProperties.Count

If sDocumentName = "" Then
sDocumentName = gApplicationWord.ActiveDocument.Name
End If

PropertyBuiltInCount = clszWorkAround.DocumentPropertyBuiltInCount(sDocumentName)

Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException

Finally
If gbDEBUG_WORD = True Or _
((IsNothing(mobjCOMException) = False Or IsNothing(mobjException) = False)) Then

Call clsError.Handle("PropertyBuiltInCount", "clsDocument", _
"return the number of 'built-in' document properties.", _
mobjCOMException, mobjException)
End If
End Try
End Function

Property_BuiltInExists

class SurroundingClass
{
public static bool DocumentPropertyBuiltInExists(string sDocumentName, string sPropertyName)
{
try
{
if (clsError.ErrorFlag() == true)
return;

int ipropertycount;
string sitemname;

{
var withBlock = gApplicationWord.documentss(sDocumentName).BuiltInDocumentProperties;
for (var ipropertycount = 1; ipropertycount <= withBlock.Count; ipropertycount++)
{
sitemname = withBlock.Item(ipropertycount).Name;

if (sitemname == sPropertyName)
{
DocumentPropertyBuiltInExists = true;
return;
}
}
}
}
catch (Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}

finally
{
if (gbDEBUG_WORD == true | ((!mobjCOMException == null) | (!mobjException == null)))
clsError.Handle("DocumentPropertyBuiltInExists", msCLASSNAME, "determine if the 'built-in' document property '" + sPropertyName + "' exists.", mobjCOMException, mobjException);
}
}


public static bool PropertyBuiltInExists(string sPropertyName, string sDocumentName = "")
{
try
{
if (clsError.ErrorFlag() == true)
return;

// Dim ipropertycount As Integer
// Dim objDocumentProperties As Office.DocumentProperties
// objDocumentProperties = _
// CType(gApplicationWord.Documents(sDocumentName).BuiltInDocumentProperties, _
// Office.DocumentProperties)
// For ipropertycount = 1 To objDocumentProperties.Count
// If objDocumentProperties.Item(ipropertycount).Name = sPropertyName Then
// PropertyBuiltInExists = True
// Exit Function
// End If
// Next ipropertycount

if (sDocumentName == "")
sDocumentName = gApplicationWord.ActiveDocument.Name;

PropertyBuiltInExists = clszWorkAround.DocumentPropertyBuiltInExists(sDocumentName, sPropertyName);
}
catch (Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}

finally
{
if (gbDEBUG_WORD == true | ((IsNothing(mobjCOMException) == false | IsNothing(mobjException) == false)))
clsError.Handle("PropertyBuiltInExists", "clsDocument", "determine if the 'built-in' document property '" + sPropertyName + "' exists.", mobjCOMException, mobjException);
}
}
}
Public Shared Function DocumentPropertyBuiltInExists(ByVal sDocumentName As String, _
ByVal sPropertyName As String) _
As Boolean

Try
If clsError.ErrorFlag() = True Then Exit Function

Dim ipropertycount As Integer
Dim sitemname As String

With gApplicationWord.documentss(sDocumentName).BuiltInDocumentProperties
For ipropertycount = 1 To .Count
sitemname = .Item(ipropertycount).Name

If sitemname = sPropertyName Then
DocumentPropertyBuiltInExists = True
Exit Function
End If
Next ipropertycount
End With

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("DocumentPropertyBuiltInExists", msCLASSNAME, _
"determine if the 'built-in' document property '" & sPropertyName & "' exists.", _
mobjCOMException, mobjException)
End If
End Try
End Function


Public Shared Function PropertyBuiltInExists(ByVal sPropertyName As String, _
Optional ByVal sDocumentName As String = "") _
As Boolean

Try
If clsError.ErrorFlag() = True Then Exit Function

'Dim ipropertycount As Integer
'Dim objDocumentProperties As Office.DocumentProperties
'objDocumentProperties = _
' CType(gApplicationWord.Documents(sDocumentName).BuiltInDocumentProperties, _
' Office.DocumentProperties)
'For ipropertycount = 1 To objDocumentProperties.Count
' If objDocumentProperties.Item(ipropertycount).Name = sPropertyName Then
' PropertyBuiltInExists = True
' Exit Function
' End If
'Next ipropertycount

If sDocumentName = "" Then
sDocumentName = gApplicationWord.ActiveDocument.Name
End If

PropertyBuiltInExists = _
clszWorkAround.DocumentPropertyBuiltInExists(sDocumentName, sPropertyName)

Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException

Finally
If gbDEBUG_WORD = True Or _
((IsNothing(mobjCOMException) = False Or IsNothing(mobjException) = False)) Then

Call clsError.Handle("PropertyBuiltInExists", "clsDocument", _
"determine if the 'built-in' document property '" & sPropertyName & "' exists.", _
mobjCOMException, mobjException)
End If
End Try
End Function

Property_BuiltInGet

class SurroundingClass
{
public static object DocumentPropertyBuiltInGet(string sDocumentName, string sPropertyName, object objDefaultValue)
{
try
{
if (clsError.ErrorFlag() == true)
return;

int ipropertycount;
string sitemname;

{
var withBlock = gApplicationWord.Documents(sDocumentName).BuiltInDocumentProperties;
for (var ipropertycount = 1; ipropertycount <= withBlock.Count; ipropertycount++)
{
sitemname = withBlock.Item(ipropertycount).Name;

if (sitemname == sPropertyName)
{
DocumentPropertyBuiltInGet = withBlock.Item(ipropertycount).Value;
return;
}
}
}
}
catch (Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}

finally
{
if (gbDEBUG_WORD == true | ((!mobjCOMException == null) | (!mobjException == null)))
clsError.Handle("DocumentPropertyBuiltInGet", msCLASSNAME, "return the 'built-in' document property '" + sPropertyName + "'.", mobjCOMException, mobjException);
}
}


public static object PropertyBuiltInGet(string sPropertyName, object objDefaultValue = null, string sDocumentName = "")
{
try
{
if (clsError.ErrorFlag() == true)
return;

// Dim objDocumentProperties As Office.DocumentProperties
// objDocumentProperties = _
// CType(gApplicationPowerPoint.Presentations(sPresentationName).BuiltInDocumentProperties, _
// Office.DocumentProperties)
// PropertyBuiltInGet = objDocumentProperties.Item(sPropertyName).Value


if (sDocumentName == "")
sDocumentName = gApplicationWord.ActiveDocument.Name;

PropertyBuiltInGet = clszWorkAround.DocumentPropertyBuiltInGet(sDocumentName, sPropertyName, objDefaultValue);
}
catch (Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}

finally
{
if (gbDEBUG_WORD == true | ((IsNothing(mobjCOMException) == false | IsNothing(mobjException) == false)))
clsError.Handle("PropertyBuiltInGet", "clsDocument", "return the 'built-in' document property '" + sPropertyName + "'.", mobjCOMException, mobjException);
}
}
}
Public Shared Function DocumentPropertyBuiltInGet(ByVal sDocumentName As String, _
ByVal sPropertyName As String, _
ByVal objDefaultValue As Object) _
As Object

Try
If clsError.ErrorFlag() = True Then Exit Function

Dim ipropertycount As Integer
Dim sitemname As String

With gApplicationWord.Documents(sDocumentName).BuiltInDocumentProperties
For ipropertycount = 1 To .Count
sitemname = .Item(ipropertycount).Name

If sitemname = sPropertyName Then
DocumentPropertyBuiltInGet = .Item(ipropertycount).Value
Exit Function
End If
Next ipropertycount
End With

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("DocumentPropertyBuiltInGet", msCLASSNAME, _
"return the 'built-in' document property '" & sPropertyName & "'.", _
mobjCOMException, mobjException)
End If
End Try
End Function


Public Shared Function PropertyBuiltInGet(ByVal sPropertyName As String, _
Optional ByVal objDefaultValue As Object = Nothing, _
Optional ByVal sDocumentName As String = "") _
As Object

Try
If clsError.ErrorFlag() = True Then Exit Function

'Dim objDocumentProperties As Office.DocumentProperties
'objDocumentProperties = _
' CType(gApplicationPowerPoint.Presentations(sPresentationName).BuiltInDocumentProperties, _
' Office.DocumentProperties)
'PropertyBuiltInGet = objDocumentProperties.Item(sPropertyName).Value


If sDocumentName = "" Then
sDocumentName = gApplicationWord.ActiveDocument.Name
End If

PropertyBuiltInGet = _
clszWorkAround.DocumentPropertyBuiltInGet(sDocumentName, sPropertyName, _
objDefaultValue)

Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException

Finally
If gbDEBUG_WORD = True Or _
((IsNothing(mobjCOMException) = False Or IsNothing(mobjException) = False)) Then

Call clsError.Handle("PropertyBuiltInGet", "clsDocument", _
"return the 'built-in' document property '" & sPropertyName & "'.", _
mobjCOMException, mobjException)
End If
End Try
End Function

Property_BuiltInSet

class SurroundingClass
{
public static void DocumentPropertyBuiltInSet(string sDocumentName, string sPropertyName, object objPropertyValue)
{
int ipropertycount;
string sitemname;

try
{
if (clsError.ErrorFlag() == true)
return;

{
var withBlock = gApplicationWord.Documents(sDocumentName).BuiltInDocumentProperties;
for (ipropertycount = 1; ipropertycount <= withBlock.Count; ipropertycount++)
{
sitemname = withBlock.Item(ipropertycount).Name;

if (sitemname == sPropertyName)
{
withBlock.Item(ipropertycount).Value = objPropertyValue;
return;
}
}
}
}

catch (Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}

finally
{
if (gbDEBUG_WORD == true | ((!mobjCOMException == null) | (!mobjException == null)))
clsError.Handle("DocumentPropertyBuiltInSet", msCLASSNAME, "change the value of the 'built-in' document property '" + sPropertyName + "'.", mobjCOMException, mobjException);
}
}


public void DocProperty_BuiltInSet(ref Word.Document objDocument, string sPropertyName, string sPropertyValue)
{
Office.DocumentProperties objDocumentProperties;

try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

if ((objDocument == null))
objDocument = Document_GetActive();

objDocumentProperties = (Office.DocumentProperties)objDocument.BuiltInDocumentProperties;

for (int ipropertycount = 1; ipropertycount <= objDocumentProperties.Count; ipropertycount++)
{
if (objDocumentProperties.Item(ipropertycount).Name == sPropertyName)
{
objDocumentProperties.Item(ipropertycount).Value = sPropertyValue;
return;
}
}
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
}
}
}
Public Shared Sub DocumentPropertyBuiltInSet(ByVal sDocumentName As String, _
ByVal sPropertyName As String, _
ByVal objPropertyValue As Object)

Dim ipropertycount As Integer
Dim sitemname As String

Try
If clsError.ErrorFlag() = True Then Exit Sub

With gApplicationWord.Documents(sDocumentName).BuiltInDocumentProperties
For ipropertycount = 1 To .Count
sitemname = .Item(ipropertycount).Name

If sitemname = sPropertyName Then
.Item(ipropertycount).Value = objPropertyValue
Exit Sub
End If
Next ipropertycount
End With


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("DocumentPropertyBuiltInSet", msCLASSNAME, _
"change the value of the 'built-in' document property '" & sPropertyName & "'.", _
mobjCOMException, mobjException)
End If
End Try
End Sub


Public Sub DocProperty_BuiltInSet(ByRef objDocument As Word.Document, _
ByVal sPropertyName As String, _
ByVal sPropertyValue As String)

Dim objDocumentProperties As Office.DocumentProperties

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

objDocumentProperties = CType(objDocument.BuiltInDocumentProperties, Office.DocumentProperties)

For ipropertycount As Integer = 1 To objDocumentProperties.Count
If objDocumentProperties.Item(ipropertycount).Name = sPropertyName Then
objDocumentProperties.Item(ipropertycount).Value = sPropertyValue
Exit Sub
End If
Next ipropertycount

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

Property_CustomAdd

class SurroundingClass
{
public void DocProperty_CustomAdd(ref Word.Document objDocument, string sPropertyName, string sPropertyValue)
{
Office.DocumentProperties objDocumentProperties;

try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

if ((objDocument == null))
objDocument = Document_GetActive();

if ((modWordObjectModel.Document_IsProtected(objDocument) == false))
{
objDocumentProperties = (Office.DocumentProperties)objDocument.CustomDocumentProperties;
objDocumentProperties.Add(sPropertyName, false, Office.MsoDocProperties.msoPropertyTypeString, sPropertyValue);
}
else
modMessages.DocProperty_UnableToAddDocumentIsProtected(sPropertyName);
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex, "add the custom property '" + sPropertyName + "' " + "with the value '" + sPropertyValue + "' " + "in the active document.");
}
}

public static void DocumentPropertyCustomAdd(string sDocumentName, string sPropertyName, string sPropertyType, object objPropertyValue)
{
try
{
if (clsError.ErrorFlag() == true)
return;

int ipropertycount;
string sitemname;

{
var withBlock = gApplicationWord.Documents(sDocumentName).CustomDocumentProperties;
withBlock.Add(Name: sPropertyName, LinkToContent: Office.MsoTriState.msoFalse, Value: objPropertyValue, Type: clsOfficeCore.PropertyTypeReturn(sPropertyType));
}
}
catch (Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}

finally
{
if (gbDEBUG_WORD == true | ((!mobjCOMException == null) | (!mobjException == null)))
clsError.Handle("DocumentPropertyCustomAdd", msCLASSNAME, "add the 'custom' document property '" + sPropertyName + "'.", mobjCOMException, mobjException);
}
}
}
Public Sub DocProperty_CustomAdd(ByRef objDocument As Word.Document, _
ByVal sPropertyName As String, _
ByVal sPropertyValue As String)

Dim objDocumentProperties As Office.DocumentProperties

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

If (modWordObjectModel.Document_IsProtected(objDocument) = False) Then

objDocumentProperties = CType(objDocument.CustomDocumentProperties, Office.DocumentProperties)
objDocumentProperties.Add(sPropertyName, False, Office.MsoDocProperties.msoPropertyTypeString, sPropertyValue)
Else
Call modMessages.DocProperty_UnableToAddDocumentIsProtected(sPropertyName)
End If

Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex, _
"add the custom property '" & sPropertyName & "' " & _
"with the value '" & sPropertyValue & "' " & _
"in the active document.")
End Try
End Sub

Public Shared Sub DocumentPropertyCustomAdd(ByVal sDocumentName As String, _
ByVal sPropertyName As String, _
ByVal sPropertyType As String, _
ByVal objPropertyValue As Object)
Try
If clsError.ErrorFlag() = True Then Exit Sub

Dim ipropertycount As Integer
Dim sitemname As String

With gApplicationWord.Documents(sDocumentName).CustomDocumentProperties

.Add(Name:=sPropertyName, _
LinkToContent:=Office.MsoTriState.msoFalse, _
Value:=objPropertyValue, _
Type:=clsOfficeCore.PropertyTypeReturn(sPropertyType))

End With

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("DocumentPropertyCustomAdd", msCLASSNAME, _
"add the 'custom' document property '" & sPropertyName & "'.", _
mobjCOMException, mobjException)
End If
End Try
End Sub

Property_CustomCount

class SurroundingClass
{
public static int PropertyCustomCount(string sDocumentName = "")
{
try
{
if (clsError.ErrorFlag() == true)
return;

// Dim objDocumentProperties As Office.DocumentProperties
// objDocumentProperties = _
// CType(gApplicationPowerPoint.Presentations(sPresentationName).BuiltInDocumentProperties, _
// Office.DocumentProperties)
// PropertyCustomCount = objDocumentProperties.Count

if (sDocumentName == "")
sDocumentName = gApplicationWord.ActiveDocument.Name;

PropertyCustomCount = clszWorkAround.DocumentPropertyCustomCount(sDocumentName);
}
catch (Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}

finally
{
if (gbDEBUG_WORD == true | ((IsNothing(mobjCOMException) == false | IsNothing(mobjException) == false)))
clsError.Handle("PropertyCustomCount", "clsDocument", "return the number of 'custom' document properties.", mobjCOMException, mobjException);
}
}

public static int DocumentPropertyCustomCount(string sDocumentName)
{
try
{
if (clsError.ErrorFlag() == true)
return;

int ipropertycount;
string sitemname;

DocumentPropertyCustomCount = gApplicationWord.Documents(sDocumentName).CustomDocumentProperties.Count;
}
catch (Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}

finally
{
if (gbDEBUG_WORD == true | ((!mobjCOMException == null) | (!mobjException == null)))
clsError.Handle("DocumentPropertyCustomCount", msCLASSNAME, "return the total number of 'custom' document properties.", mobjCOMException, mobjException);
}
}
}
Public Shared Function PropertyCustomCount(Optional ByVal sDocumentName As String = "") _
As Integer

Try
If clsError.ErrorFlag() = True Then Exit Function

'Dim objDocumentProperties As Office.DocumentProperties
'objDocumentProperties = _
' CType(gApplicationPowerPoint.Presentations(sPresentationName).BuiltInDocumentProperties, _
' Office.DocumentProperties)
'PropertyCustomCount = objDocumentProperties.Count

If sDocumentName = "" Then
sDocumentName = gApplicationWord.ActiveDocument.Name
End If

PropertyCustomCount = clszWorkAround.DocumentPropertyCustomCount(sDocumentName)

Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException

Finally
If gbDEBUG_WORD = True Or _
((IsNothing(mobjCOMException) = False Or IsNothing(mobjException) = False)) Then

Call clsError.Handle("PropertyCustomCount", "clsDocument", _
"return the number of 'custom' document properties.", _
mobjCOMException, mobjException)
End If
End Try
End Function

Public Shared Function DocumentPropertyCustomCount(ByVal sDocumentName As String) _
As Integer

Try
If clsError.ErrorFlag() = True Then Exit Function

Dim ipropertycount As Integer
Dim sitemname As String

DocumentPropertyCustomCount = _
gApplicationWord.Documents(sDocumentName).CustomDocumentProperties.Count

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("DocumentPropertyCustomCount", msCLASSNAME, _
"return the total number of 'custom' document properties.", _
mobjCOMException, mobjException)
End If
End Try
End Function

Property_CustomDelete

public static void PropertyCustomDelete(string sPropertyName, string sDocumentName = "")
{
try
{
if (clsError.ErrorFlag() == true)
return;

clszWorkAround.DocumentPropertyCustomDelete(sDocumentName, sPropertyName);
}
catch (Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}

finally
{
if (gbDEBUG_WORD == true | ((IsNothing(mobjCOMException) == false | IsNothing(mobjException) == false)))
clsError.Handle("PropertyCustomDelete", "clsDocument", "delete the 'custom' presentation property '" + sPropertyName + "'.", mobjCOMException, mobjException);
}
}

public static void DocumentPropertyCustomDelete(string sDocumentName, string sPropertyName)
{
try
{
if (clsError.ErrorFlag() == true)
return;

int ipropertycount;
string sitemname;

{
var withBlock = gApplicationWord.Documents(sDocumentName).CustomDocumentProperties;
for (var ipropertycount = 1; ipropertycount <= withBlock.Count; ipropertycount++)
{
sitemname = withBlock.Item(ipropertycount).Name;

if (sitemname == sPropertyName)
{
withBlock.Item(ipropertycount).Delete();
return;
}
}
}
}
catch (Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}

finally
{
if (gbDEBUG_WORD == true | ((!mobjCOMException == null) | (!mobjException == null)))
clsError.Handle("DocumentPropertyCustomDelete", msCLASSNAME, "delete the 'custom' document property '" + sPropertyName + "'.", mobjCOMException, mobjException);
}
}
Public Shared Sub PropertyCustomDelete(ByVal sPropertyName As String, _
Optional ByVal sDocumentName As String = "")

Try
If clsError.ErrorFlag() = True Then Exit Sub

Call clszWorkAround.DocumentPropertyCustomDelete(sDocumentName, sPropertyName)

Catch objCOMException As System.Runtime.InteropServices.COMException
mobjCOMException = objCOMException
Catch objException As Exception
mobjException = objException

Finally
If gbDEBUG_WORD = True Or _
((IsNothing(mobjCOMException) = False Or IsNothing(mobjException) = False)) Then

Call clsError.Handle("PropertyCustomDelete", "clsDocument", _
"delete the 'custom' presentation property '" & sPropertyName & "'.", _
mobjCOMException, mobjException)
End If
End Try
End Sub

Public Shared Sub DocumentPropertyCustomDelete(ByVal sDocumentName As String, _
ByVal sPropertyName As String)

Try
If clsError.ErrorFlag() = True Then Exit Sub

Dim ipropertycount As Integer
Dim sitemname As String

With gApplicationWord.Documents(sDocumentName).CustomDocumentProperties
For ipropertycount = 1 To .Count
sitemname = .Item(ipropertycount).Name

If sitemname = sPropertyName Then
.Item(ipropertycount).Delete()
Exit Sub
End If
Next ipropertycount
End With

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("DocumentPropertyCustomDelete", msCLASSNAME, _
"delete the 'custom' document property '" & sPropertyName & "'.", _
mobjCOMException, mobjException)
End If
End Try
End Sub

Property_CustomExists

class SurroundingClass
{
public bool Property_CustomExists(ref Word.Document objDocument, string sPropertyName)
{
Office.DocumentProperties objDocumentProperties;

try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

if ((objDocument == null))
objDocument = Document_GetActive();

objDocumentProperties = (Office.DocumentProperties)objDocument.CustomDocumentProperties;

for (System.Int32 ipropertycount = 1; ipropertycount <= objDocumentProperties.Count; ipropertycount++)
{
if (objDocumentProperties.Item(ipropertycount).Name == sPropertyName)
{
DocProperty_CustomExists = true;
return;
}
}
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
}
}

public static bool DocumentPropertyCustomExists(string sDocumentName, string sPropertyName)
{
try
{
if (clsError.ErrorFlag() == true)
return;

int ipropertycount;
string sitemname;

{
var withBlock = gApplicationWord.Documents(sDocumentName).CustomDocumentProperties;
for (var ipropertycount = 1; ipropertycount <= withBlock.Count; ipropertycount++)
{
sitemname = withBlock.Item(ipropertycount).Name;

if (sitemname == sPropertyName)
{
DocumentPropertyCustomExists = true;
return;
}
}
}
}
catch (Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}

finally
{
if (gbDEBUG_WORD == true | ((!mobjCOMException == null) | (!mobjException == null)))
clsError.Handle("DocumentPropertyCustomExists", msCLASSNAME, "determine if the 'custom' document property '" + sPropertyName + "' exists.", mobjCOMException, mobjException);
}
}
}
Public Function Property_CustomExists(ByRef objDocument As Word.Document, _
ByVal sPropertyName As String) As Boolean

Dim objDocumentProperties As Office.DocumentProperties

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

If (objDocument Is Nothing) Then objDocument = Document_GetActive()

objDocumentProperties = CType(objDocument.CustomDocumentProperties, Office.DocumentProperties)

For ipropertycount As System.Int32 = 1 To objDocumentProperties.Count
If objDocumentProperties.Item(ipropertycount).Name = sPropertyName Then
DocProperty_CustomExists = True
Exit Function
End If
Next ipropertycount

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

Public Shared Function DocumentPropertyCustomExists(ByVal sDocumentName As String, _
ByVal sPropertyName As String) _
As Boolean

Try
If clsError.ErrorFlag() = True Then Exit Function

Dim ipropertycount As Integer
Dim sitemname As String

With gApplicationWord.Documents(sDocumentName).CustomDocumentProperties
For ipropertycount = 1 To .Count
sitemname = .Item(ipropertycount).Name

If sitemname = sPropertyName Then
DocumentPropertyCustomExists = True
Exit Function
End If
Next ipropertycount
End With

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("DocumentPropertyCustomExists", msCLASSNAME, _
"determine if the 'custom' document property '" & sPropertyName & "' exists.", _
mobjCOMException, mobjException)
End If
End Try
End Function

Property_CustomGet


public object DocProperty_CustomGet(ref Word.Document objDocument, string sPropertyName, bool bInformUser = false)
{
Office.DocumentProperties objDocumentProperties;

try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
{
return null; return;
}

if ((objDocument == null))
objDocument = Document_GetActive();

objDocumentProperties = (Office.DocumentProperties)objDocument.CustomDocumentProperties;

for (int ipropertycount = 1; ipropertycount <= objDocumentProperties.Count; ipropertycount++)
{
if (objDocumentProperties.Item(ipropertycount).Name == sPropertyName)
{
DocProperty_CustomGet = objDocumentProperties.Item(ipropertycount).Value;
Tracer_Add2("DOCUMENT", "The document property '" + sPropertyName + "' exists.");
return;
}
}

Tracer_Add2("DOCUMENT", "The document property '" + sPropertyName + "' does not exist.");
if ((bInformUser == true))
modMessages.DocProperty_DoesNotExist(sPropertyName);
return "";
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex, "get the custom property '" + sPropertyName + "' " + "from the active document.", false);
return "";
}
}

public static object DocumentPropertyCustomGet(string sDocumentName, string sPropertyName, object objDefaultValue)
{
try
{
if (clsError.ErrorFlag() == true)
return;

int ipropertycount;
string sitemname;

{
var withBlock = gApplicationWord.Documents(sDocumentName).CustomDocumentProperties;
for (var ipropertycount = 1; ipropertycount <= withBlock.Count; ipropertycount++)
{
sitemname = withBlock.Item(ipropertycount).Name;

if (sitemname == sPropertyName)
{
DocumentPropertyCustomGet = withBlock.Item(ipropertycount).Value;
return;
}
}
}
}
catch (Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}

finally
{
if (gbDEBUG_WORD == true | ((!mobjCOMException == null) | (!mobjException == null)))
clsError.Handle("DocumentPropertyCustomGet", msCLASSNAME, "return the 'custom' document property '" + sPropertyName + "'.", mobjCOMException, mobjException);
}
}
Public Function DocProperty_CustomGet(ByRef objDocument As Word.Document, _
ByVal sPropertyName As String, _
Optional ByVal bInformUser As Boolean = False) As Object

Dim objDocumentProperties As Office.DocumentProperties

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

objDocumentProperties = CType(objDocument.CustomDocumentProperties, Office.DocumentProperties)

For ipropertycount As Integer = 1 To objDocumentProperties.Count
If objDocumentProperties.Item(ipropertycount).Name = sPropertyName Then
DocProperty_CustomGet = objDocumentProperties.Item(ipropertycount).Value
Tracer_Add2("DOCUMENT", "The document property '" & sPropertyName & "' exists.")
Exit Function
End If
Next ipropertycount

Tracer_Add2("DOCUMENT", "The document property '" & sPropertyName & "' does not exist.")
If (bInformUser = True) Then
modMessages.DocProperty_DoesNotExist(sPropertyName)
End If
Return ""

Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex, _
"get the custom property '" & sPropertyName & "' " & _
"from the active document.", False)
Return ""
End Try
End Function

Public Shared Function DocumentPropertyCustomGet(ByVal sDocumentName As String, _
ByVal sPropertyName As String, _
ByVal objDefaultValue As Object) _
As Object

Try
If clsError.ErrorFlag() = True Then Exit Function

Dim ipropertycount As Integer
Dim sitemname As String

With gApplicationWord.Documents(sDocumentName).CustomDocumentProperties
For ipropertycount = 1 To .Count
sitemname = .Item(ipropertycount).Name

If sitemname = sPropertyName Then
DocumentPropertyCustomGet = .Item(ipropertycount).Value
Exit Function
End If
Next ipropertycount
End With

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("DocumentPropertyCustomGet", msCLASSNAME, _
"return the 'custom' document property '" & sPropertyName & "'.", _
mobjCOMException, mobjException)
End If
End Try
End Function

Property_CustomSet

class SurroundingClass
{
public void DocProperty_CustomSet(ref Word.Document objDocument, string sPropertyName, string sPropertyValue)
{
Office.DocumentProperties objDocumentProperties;

try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;

if ((objDocument == null))
objDocument = Document_GetActive();

objDocumentProperties = (Office.DocumentProperties)objDocument.CustomDocumentProperties;

for (int ipropertycount = 1; ipropertycount <= objDocumentProperties.Count; ipropertycount++)
{
if (objDocumentProperties.Item(ipropertycount).Name == sPropertyName)
{
objDocumentProperties.Item(ipropertycount).Value = sPropertyValue;
return;
}
}
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
}
}

public static void DocumentPropertyCustomSet(string sDocumentName, string sPropertyName, object objPropertyValue)
{
try
{
if (clsError.ErrorFlag() == true)
return;


int ipropertycount;
string sitemname;

{
var withBlock = gApplicationWord.Documents(sDocumentName).CustomDocumentProperties;
for (var ipropertycount = 1; ipropertycount <= withBlock.Count; ipropertycount++)
{
sitemname = withBlock.Item(ipropertycount).Name;

if (sitemname == sPropertyName)
{
withBlock.Item(ipropertycount).Value = objPropertyValue;
return;
}
}
}
}

catch (Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}

finally
{
if (gbDEBUG_WORD == true | ((!mobjCOMException == null) | (!mobjException == null)))
clsError.Handle("DocumentPropertyCustomSet", msCLASSNAME, "change the value of the 'custom' document property '" + sPropertyName + ".", mobjCOMException, mobjException);
}
}
}
Public Sub DocProperty_CustomSet(ByRef objDocument As Word.Document, _
ByVal sPropertyName As String, _
ByVal sPropertyValue As String)

Dim objDocumentProperties As Office.DocumentProperties

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

objDocumentProperties = CType(objDocument.CustomDocumentProperties, Office.DocumentProperties)

For ipropertycount As Integer = 1 To objDocumentProperties.Count
If objDocumentProperties.Item(ipropertycount).Name = sPropertyName Then
objDocumentProperties.Item(ipropertycount).Value = sPropertyValue
Exit Sub
End If
Next ipropertycount

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

Public Shared Sub DocumentPropertyCustomSet(ByVal sDocumentName As String, _
ByVal sPropertyName As String, _
ByVal objPropertyValue As Object)

Try
If clsError.ErrorFlag() = True Then Exit Sub


Dim ipropertycount As Integer
Dim sitemname As String

With gApplicationWord.Documents(sDocumentName).CustomDocumentProperties
For ipropertycount = 1 To .Count
sitemname = .Item(ipropertycount).Name

If sitemname = sPropertyName Then
.Item(ipropertycount).Value = objPropertyValue
Exit Sub
End If
Next ipropertycount
End With


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("DocumentPropertyCustomSet", msCLASSNAME, _
"change the value of the 'custom' document property '" & sPropertyName & ".", _
mobjCOMException, mobjException)
End If
End Try
End Sub

RulerDisplayed

public static bool RulerDisplayed()
{
try
{
RulerDisplayed = gApplicationWord.ActiveWindow.ActivePane.DisplayRulers();
}
catch (Runtime.InteropServices.COMException objCOMException)
{
gobjCOMException = objCOMException;
}
catch (Exception objException)
{
gobjException = objException;
}

finally
{
if (gbDEBUG_WORD == true | ((IsNothing(gobjCOMException) == false | IsNothing(gobjException) == false)))
clsError.Handle("RulerDisplayed", "clsPowerPoint", "determine if the ruler is currently displayed..", gobjCOMException, gobjException);
}
}
Public Shared Function RulerDisplayed() As Boolean

Try

RulerDisplayed = gApplicationWord.ActiveWindow.ActivePane.DisplayRulers()

Catch objCOMException As System.Runtime.InteropServices.COMException
gobjCOMException = objCOMException
Catch objException As Exception
gobjException = objException

Finally
If gbDEBUG_WORD = True Or _
((IsNothing(gobjCOMException) = False Or IsNothing(gobjException) = False)) Then

Call clsError.Handle("RulerDisplayed", "clsPowerPoint", _
"determine if the ruler is currently displayed..", _
gobjCOMException, gobjException)
End If
End Try
End Function

SelectView

public static void SelectView(string sViewName)
{
try
{
if (clsError.ErrorFlag() == true)
return;

switch (sViewName)
{
case "Master":
{
gApplicationWord.ActiveWindow.ActivePane.View.Type = Word.WdViewType.wdMasterView;
break;
}

case "Normal":
{
gApplicationWord.ActiveWindow.ActivePane.View.Type = Word.WdViewType.wdNormalView;
break;
}

case "Outline":
{
gApplicationWord.ActiveWindow.ActivePane.View.Type = Word.WdViewType.wdOutlineView;
break;
}

case "PrintPreview":
{
gApplicationWord.ActiveWindow.ActivePane.View.Type = Word.WdViewType.wdPrintPreview;
break;
}

case "Print":
{
gApplicationWord.ActiveWindow.ActivePane.View.Type = Word.WdViewType.wdPrintView;
break;
}

case "Web":
{
gApplicationWord.ActiveWindow.ActivePane.View.Type = Word.WdViewType.wdWebView;
break;
}

default:
{
System.Windows.Forms.MessageBox.Show("Something else", "Document_WindowSelect");
break;
}
}
}
catch (Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}

finally
{
if (gbDEBUG_WORD == true | ((!mobjCOMException == null) | (!mobjException == null)))
clsError.Handle("SelectView", msCLASSNAME, "select the view '" + sViewName + "'.", mobjCOMException, mobjException);
}
}
Public Shared Sub SelectView(ByVal sViewName As String)

Try
If clsError.ErrorFlag() = True Then Exit Sub

Select Case sViewName
Case "Master"
gApplicationWord.ActiveWindow.ActivePane.View.Type = Word.WdViewType.wdMasterView

Case "Normal"
gApplicationWord.ActiveWindow.ActivePane.View.Type = Word.WdViewType.wdNormalView

Case "Outline"
gApplicationWord.ActiveWindow.ActivePane.View.Type = Word.WdViewType.wdOutlineView

Case "PrintPreview"
gApplicationWord.ActiveWindow.ActivePane.View.Type = Word.WdViewType.wdPrintPreview

Case "Print"
gApplicationWord.ActiveWindow.ActivePane.View.Type = Word.WdViewType.wdPrintView

Case "Web"
gApplicationWord.ActiveWindow.ActivePane.View.Type = Word.WdViewType.wdWebView


Case Else
Call System.Windows.Forms.MessageBox.Show( _
"Something else", "Document_WindowSelect")

End Select

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("SelectView", msCLASSNAME, _
"select the view '" & sViewName & "'.", _
mobjCOMException, mobjException)
End If
End Try
End Sub

SettingsFile_Exists

public bool SettingsFile_Exists(bool bInformUser = true)
{
try
{
return modGeneral.File_Exists(SettingsFile_Return, bInformUser);
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
return false;
}
}
Public Function SettingsFile_Exists(Optional ByVal bInformUser As Boolean = True) As Boolean

Try
Return modGeneral.File_Exists(SettingsFile_Return, bInformUser)

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

SettingsFile_Retrieve

public clsSettingsFile SettingsFile_Retrieve()
{
clsSettingsFile objsettingsfile;

try
{
if ((modSpecific.SettingsFile_Exists(false) == false))
{
gSettingsFile = new clsSettingsFile();

objsettingsfile = gSettingsFile;

modSpecific.SettingsFile_Save();

Tracer_Add2("SYSTEM", "User Settings File - Created: " + objsettingsfile.UserProfileFolder + objsettingsfile.UserSettingsFileName);
}
else
{
objsettingsfile = (clsSettingsFile)modGeneral.XML_DeserializeFromXmlFile(SettingsFile_Return, SettingsFile_GetType);

// default to no detailed logging
objsettingsfile.DisplayDetailedLogging = false;
objsettingsfile.GrantFullAccess = false;

Tracer_Add2("SYSTEM", "User Settings File - Read: " + objsettingsfile.UserProfileFolder + objsettingsfile.UserSettingsFileName);
}

modGeneral.LogFile_Purge(objsettingsfile);
modGeneral.Tracer_Start("WORD", objsettingsfile);

return objsettingsfile;
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
return null/* TODO Change to default(_) if this is not a reference type */;
}
}
Public Function SettingsFile_Retrieve() As clsSettingsFile

Dim objsettingsfile As clsSettingsFile

Try
If (modSpecific.SettingsFile_Exists(False) = False) Then

gSettingsFile = New clsSettingsFile

objsettingsfile = gSettingsFile

Call modSpecific.SettingsFile_Save()

Call Tracer_Add2("SYSTEM", "User Settings File - Created: " & objsettingsfile.UserProfileFolder & objsettingsfile.UserSettingsFileName)

Else
objsettingsfile = CType(modGeneral.XML_DeserializeFromXmlFile(SettingsFile_Return, SettingsFile_GetType), clsSettingsFile)

'default to no detailed logging
objsettingsfile.DisplayDetailedLogging = False
objsettingsfile.GrantFullAccess = False

Call Tracer_Add2("SYSTEM", "User Settings File - Read: " & objsettingsfile.UserProfileFolder & objsettingsfile.UserSettingsFileName)
End If

modGeneral.LogFile_Purge(objsettingsfile)
modGeneral.Tracer_Start("WORD", objsettingsfile)

Return objsettingsfile

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

SettingsFile_Return

public string SettingsFile_Return()
{
string sfullfolderpath;

sfullfolderpath = My.Settings.FOLDER_USERPROFILE.Replace("%APPLICATIONDATA%", System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData)) + "UserSettings.xml";

return sfullfolderpath;
}
Public Function SettingsFile_Return() As String
Dim sfullfolderpath As String

sfullfolderpath = My.Settings.FOLDER_USERPROFILE.Replace("%APPLICATIONDATA%", _
System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData)) & _
"UserSettings.xml"

Return sfullfolderpath
End Function

SettingsFile_Save

public void SettingsFile_Save()
{
string sfullfolderpath;

try
{
if ((gSettingsFile == null))
{
if (SettingsFile_Exists(true) == true)
modMessages.SettingsFile_CannotBeUpdated();
return;
}
else
{
modGeneral.XML_SerializeToXmlFile(gSettingsFile, gSettingsFile.UserProfileFolder + gSettingsFile.UserSettingsFileName);

sfullfolderpath = My.Settings.FOLDER_USERPROFILE.Replace("%APPLICATIONDATA%", System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData)) + "UserSettings.xml";

Tracer_Add2("SYSTEM", "User Settings File - Saved: " + sfullfolderpath);
}
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
}
}
Public Sub SettingsFile_Save()

Dim sfullfolderpath As String

Try

If (gSettingsFile Is Nothing) Then
If SettingsFile_Exists(True) = True Then
Call modMessages.SettingsFile_CannotBeUpdated()
End If
Exit Sub
Else
modGeneral.XML_SerializeToXmlFile(gSettingsFile, _
gSettingsFile.UserProfileFolder & gSettingsFile.UserSettingsFileName)

sfullfolderpath = My.Settings.FOLDER_USERPROFILE.Replace("%APPLICATIONDATA%", _
System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData)) & _
"UserSettings.xml"

Call Tracer_Add2("SYSTEM", "User Settings File - Saved: " & sfullfolderpath)
End If

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

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