C# Snippets


CursorInBlankPara

Public Function CursorInBlankPara() As Boolean

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

If gApplicationWord.Selection.Paragraphs(1).Range.End = gApplicationWord.Selection.Paragraphs(1).Range.Start + 1 Then
Return True
System.Windows.Forms.MessageBox.Show("In blank para")
End If
If gApplicationWord.Selection.Type = gApplicationWord.Selection.Paragraphs(1).Range.Start + 1 Then
Return True
System.Windows.Forms.MessageBox.Show("In blank para")
End If

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

FindStringMakeBold

Public Sub Text_FindStringMakeBold(ByRef objDocument As Word.Document)
Dim objSelection As Word.Range

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

objSelection = CType(gApplicationWord.Selection.Range, Word.Range)

Call modWordObjectModel.Find_StringMakeBold(objSelection, "\*\<\/b\>")

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

IsAtBeginningOfSection

Public Function Selection_IsAtBeginningOfSection() As Boolean

Dim oPara As Word.Paragraph
Dim intPreviousSection As Integer
Dim intCurrentSection As Integer

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

oPara = Globals.ThisAddIn.Application.Selection.Range.Paragraphs(1)

intCurrentSection = oPara.Range.Sections(1).Index

If intCurrentSection = 1 Then
Return False
Else

intPreviousSection = oPara.Previous(1).Range.Sections.Last.Index

If intPreviousSection < intCurrentSection Then
Return True
Else
Return False
End If
End If

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

End Function

PasteSpecialInLineShape

Public Sub Text_PasteSpecialInLineShape(ByRef objDocument As Word.Document)

Dim iStartCount As System.Int32
Dim iEndCount As System.Int32

Try
iStartCount = objDocument.Shapes.Count

If (modWordObjectModel.Dialogs_PasteSpecial() = True) Then
iEndCount = objDocument.Shapes.Count

If (iEndCount > iStartCount) Then
'this generates an error if track changes are switched on
objDocument.Shapes(iEndCount).ConvertToInlineShape()
End If
End If

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

'Public Sub Selection_PasteSpecial()

' 'Forces pasted objects to be Inline rather than Floating,
' 'except in the case of objects that can't be pasted Inline,
' 'such as text boxes

' Dim StartCount As Long
' Dim EndCount As Long

' On Error Resume Next
' 'To allow for text boxes, etc.

' modWordObjectModel.Document_Unprotect()

' StartCount = gApplicationWord.ActiveDocument.Shapes.Count
' gApplicationWord.Dialogs(Word.WdWordDialog.wdDialogEditPasteSpecial).Show()
' EndCount = gApplicationWord.ActiveDocument.Shapes.Count
' If EndCount > StartCount Then
' gApplicationWord.ActiveDocument.Shapes(EndCount).ConvertToInlineShape()
' End If

' modWordObjectModel.Document_Protect()
' On Error GoTo 0

'End Sub

Spacing

Public Sub Text_Spacing(ByVal sngSpacing As Single, _
Optional ByVal objRange As Word.Range = Nothing)

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

If (objRange Is Nothing) Then
objRange = gApplicationWord.Selection.Range
End If

objRange.Font.Spacing = sngSpacing

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

TotalLinesInRange

Public Function Text_TotalLinesInRange(ByVal oRange As Word.Range) As Long

Dim ltotallines As Long

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

If Not (oRange Is Nothing) Then
ltotallines = oRange.ComputeStatistics(Word.WdStatistic.wdStatisticLines)
End If

Return ltotallines

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

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