C# Snippets


ApplySimpleRowFormatting

Public Function Table_ApplySimpleRowFormatting(ByVal objTable As Word.Table, _
ByVal iNoOfHeadingRows As Integer, _
ByVal sRowType As String, _
ByVal bUseAlternateShading As Boolean) As Boolean

Const sPROCNAME As String = "Table_ApplySimpleRowFormatting"

Dim objRow As Word.Row
Dim objCell As Word.Cell

Dim blnIsAltRow As Boolean
Dim intStartRow As Integer
Dim intLastRow As Integer
Dim intCurrentRowIndex As Integer
Dim strTargetStyle As String

On Error GoTo ErrorHandler

strTargetStyle = ""

If (sRowType = "Standard Row") Then
strTargetStyle = "B-Table Text"
intStartRow = iNoOfHeadingRows + 1
intLastRow = objTable.Rows.Count
End If
If (sRowType = "Heading Row") Then
strTargetStyle = "B-Table Heading"
intStartRow = 1
intLastRow = iNoOfHeadingRows
End If

intCurrentRowIndex = intStartRow
blnIsAltRow = True

If Table_HasVerticallyMergedCells(objTable) = False Then

For Each objRow In objTable.Range.Rows

If (objRow.Index >= intStartRow) And (objRow.Index <= intLastRow) Then

If intCurrentRowIndex < objRow.Index Then
intCurrentRowIndex = intCurrentRowIndex + 1

If (sRowType = "Standard Row") Then
blnIsAltRow = Not blnIsAltRow
End If
End If

With objRow.Cells
.Shading.Texture = Word.WdTextureIndex.wdTextureNone
.Shading.ForegroundPatternColor = Word.WdColor.wdColorAutomatic
.Shading.BackgroundPatternColor = Word.WdColor.wdColorAutomatic
End With

objRow.Range.Style = strTargetStyle

If (sRowType = "Heading Row") Then
With objRow.Cells.Shading
.ForegroundPatternColor = Word.WdColor.wdColorAutomatic
.BackgroundPatternColor = RGB(131, 163, 175)
End With
With objRow.Cells.Borders(Word.WdBorderType.wdBorderBottom)
.LineStyle = Word.WdLineStyle.wdLineStyleSingle
.Color = Word.WdColor.wdColorWhite
.LineWidth = Word.WdLineWidth.wdLineWidth150pt
End With
End If

If (sRowType = "Standard Row") And (bUseAlternateShading = True) Then
If blnIsAltRow Then
objRow.Cells.Shading.ForegroundPatternColor = Word.WdColor.wdColorAutomatic
objRow.Cells.Shading.BackgroundPatternColor = RGB(213, 227, 235)
End If
End If

'Add the bottom border
If (objRow.Index = objTable.Range.Rows.Count) Then

With objRow.Cells.Borders(Word.WdBorderType.wdBorderBottom)
.LineStyle = Word.WdLineStyle.wdLineStyleSingle
.LineWidth = Word.WdLineWidth.wdLineWidth075pt
.Color = RGB(131, 163, 175)
End With
End If
End If
Next objRow

Else

For Each objCell In objTable.Range.Cells

If (objCell.RowIndex >= intStartRow) And (objCell.RowIndex <= intLastRow) Then
If intCurrentRowIndex < objCell.RowIndex Then
intCurrentRowIndex = intCurrentRowIndex + 1

If (sRowType = "Standard Row") Then
blnIsAltRow = Not blnIsAltRow
End If
End If

With objCell
.Shading.Texture = Word.WdTextureIndex.wdTextureNone
.Shading.ForegroundPatternColor = Word.WdColor.wdColorAutomatic
.Shading.BackgroundPatternColor = Word.WdColor.wdColorAutomatic
End With

objCell.Range.Style = strTargetStyle

If (sRowType = "Heading Row") Then
With objCell.Shading
.ForegroundPatternColor = Word.WdColor.wdColorAutomatic
.BackgroundPatternColor = CType(Microsoft.VisualBasic.RGB(131, 163, 175), Word.WdColor)
End With
With objCell.Borders(Word.WdBorderType.wdBorderBottom)
.LineStyle = Word.WdLineStyle.wdLineStyleSingle
.Color = Word.WdColor.wdColorWhite
.LineWidth = Word.WdLineWidth.wdLineWidth150pt
End With
End If

If (sRowType = "Standard Row") And (bUseAlternateShading = True) Then
If blnIsAltRow Then
objCell.Shading.ForegroundPatternColor = Word.WdColor.wdColorAutomatic
objCell.Shading.BackgroundPatternColor = CType(Microsoft.VisualBasic.RGB(213, 227, 235), Word.WdColor)
End If
End If

'Add the bottom border
If (objCell.RowIndex = objTable.Range.Rows.Count) Then
With objCell.Borders(Word.WdBorderType.wdBorderBottom)
.LineStyle = Word.WdLineStyle.wdLineStyleSingle
.LineWidth = Word.WdLineWidth.wdLineWidth075pt
.Color = CType(Microsoft.VisualBasic.RGB(131, 163, 175), Word.WdColor)
End With
End If
End If
Next objCell
End If

With objTable.Range.Cells(1)
.LeftPadding = gApplicationWord.InchesToPoints(0.01)
.RightPadding = gApplicationWord.InchesToPoints(0.01)
.TopPadding = 0
.BottomPadding = 0
End With

Exit Function
ErrorHandler:
Call Error_Handle(msMODULENAME, sPROCNAME, Err.Number, Err.Description)
End Function

Messages_NotInOne

Public Sub Table_NotInOne()
System.Windows.Forms.MessageBox.Show( _
"The selection is not within a table.", _
My.Settings.APP_WINFORMS_TITLE, _
System.Windows.Forms.MessageBoxButtons.OK, _
System.Windows.Forms.MessageBoxIcon.Information)
End Sub
'**************************************************************************************

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