C# Snippets
CharactersExtend
Public Shared Sub CharactersExtend(ByVal sDirection As String, _
ByVal iNoOfChars As Integer)
Try
If clsError.ErrorFlag() = True Then Exit Sub
If sDirection = "Left" Then
gApplicationWord.Selection.MoveLeft(Unit:=Word.WdUnits.wdCharacter, _
Count:=CType(iNoOfChars, System.Object), _
Extend:=Word.WdMovementType.wdExtend)
End If
If sDirection = "Right" Then
gApplicationWord.Selection.MoveRight(Unit:=Word.WdUnits.wdCharacter, _
Count:=CType(iNoOfChars, System.Object), _
Extend:=Word.WdMovementType.wdExtend)
End If
If sDirection = "Up" Then
gApplicationWord.Selection.MoveUp(Unit:=Word.WdUnits.wdCharacter, _
Count:=CType(iNoOfChars, System.Object), _
Extend:=Word.WdMovementType.wdExtend)
End If
If sDirection = "Down" Then
gApplicationWord.Selection.MoveDown(Unit:=Word.WdUnits.wdCharacter, _
Count:=CType(iNoOfChars, System.Object), _
Extend:=Word.WdMovementType.wdExtend)
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("CharactersExtend", msCLASSNAME, _
"extend the current selection " & iNoOfChars & _
" characters to the '" & sDirection & "'.", _
mobjCOMException, mobjException)
End If
End Try
End Sub
CharactersMove
Public Shared Sub CharactersMove(ByVal sDirection As String, _
ByVal iNoOfChars As Integer)
Try
If clsError.ErrorFlag() = True Then Exit Sub
If sDirection = "Left" Then
gApplicationWord.Selection.MoveLeft(Unit:=Word.WdUnits.wdCharacter, _
Count:=CType(iNoOfChars, System.Object), _
Extend:=Word.WdMovementType.wdMove)
End If
If sDirection = "Right" Then
gApplicationWord.Selection.MoveRight(Unit:=Word.WdUnits.wdCharacter, _
Count:=CType(iNoOfChars, System.Object), _
Extend:=Word.WdMovementType.wdMove)
End If
If sDirection = "Up" Then
gApplicationWord.Selection.MoveUp(Unit:=Word.WdUnits.wdCharacter, _
Count:=CType(iNoOfChars, System.Object), _
Extend:=Word.WdMovementType.wdMove)
End If
If sDirection = "Down" Then
gApplicationWord.Selection.MoveDown(Unit:=Word.WdUnits.wdCharacter, _
Count:=CType(iNoOfChars, System.Object), _
Extend:=Word.WdMovementType.wdMove)
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("CharactersMove", msCLASSNAME, _
"move " & iNoOfChars & " characters to the '" & sDirection & "'.", _
mobjCOMException, mobjException)
End If
End Try
End Sub
ColourChange
Public Shared Sub ColourChange(ByVal objColor As System.Drawing.Color)
Try
If clsError.ErrorFlag() = True Then Exit Sub
gApplicationWord.Selection.Font.Color = _
CType(Microsoft.VisualBasic.RGB(objColor.R, objColor.G, objColor.B), Word.WdColor)
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("ColourChange", msCLASSNAME, _
"change the colour of the selection.", _
mobjCOMException, mobjException)
End If
End Try
End Sub
HasAnyShapes
Public Shared Function HasAnyShapes() As Boolean
Try
If clsError.ErrorFlag() = True Then Exit Function
If gApplicationWord.Selection.Range.ShapeRange.Count > 0 Then
HasAnyShapes = True
End If
Catch objCOMException As System.Runtime.InteropServices.COMException
HasAnyShapes = False
Catch objException As Exception
HasAnyShapes = False
Finally
End Try
End Function
StoryMoveTop
Public Shared Sub StoryMoveTop()
Try
If clsError.ErrorFlag() = True Then Exit Sub
gApplicationWord.Selection.HomeKey(Unit:=Word.WdUnits.wdStory)
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("StoryMoveTop", msCLASSNAME, _
"move to the top of the document.", _
mobjCOMException, mobjException)
End If
End Try
End Sub
StyleChange
Public Shared Sub StyleChange(ByVal sStyleName As String)
Try
If clsError.ErrorFlag() = True Then Exit Sub
If gApplicationWord Is Nothing Then
Call clszMessagesGeneral.Message("StyleChange - gApplicationWord is Nothing")
End If
If sStyleName.Length = 0 Then
Call clszMessagesGeneral.Message("sStyleName.Length = 0")
End If
gApplicationWord.Selection.Style = gApplicationWord.ActiveDocument.Styles(sStyleName)
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("StyleChange", msCLASSNAME, _
"change the style of the selection.", _
mobjCOMException, mobjException)
End If
End Try
End Sub
TabInsert
Public Shared Sub TabInsert(ByVal sTabType As String, _
ByVal sngMillimeters As Single)
Try
If clsError.ErrorFlag() = True Then Exit Sub
Dim objTabAlignment As Word.WdTabAlignment
Select Case sTabType
Case "Left" : objTabAlignment = Word.WdTabAlignment.wdAlignTabLeft
Case "Right" : objTabAlignment = Word.WdTabAlignment.wdAlignTabRight
Case "Centre" : objTabAlignment = Word.WdTabAlignment.wdAlignTabCenter
Case "Decimal" : objTabAlignment = Word.WdTabAlignment.wdAlignTabDecimal
Case "Bar" : objTabAlignment = Word.WdTabAlignment.wdAlignTabBar
Case "List" : objTabAlignment = Word.WdTabAlignment.wdAlignTabList
End Select
gApplicationWord.Selection.ParagraphFormat.TabStops.Add( _
Position:=gApplicationWord.MillimetersToPoints(sngMillimeters), _
Alignment:=CType(objTabAlignment, System.Object), _
Leader:=Word.WdTabLeader.wdTabLeaderSpaces)
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("StoryMoveTop", msCLASSNAME, _
"move to the top of the document.", _
mobjCOMException, mobjException)
End If
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