M
Mike Davis
Hi all,
I have a C# console app that I'm building to automate some Word
functionality. I would like to add code to that app that will conditionally
color some table cell backgrounds based on the text within the cell.
My coding experience is generally limited, especially when trying to convert
from one language to another.
That said, I have the following VBA code that works fine within Word 2003 --
it's assigned to a button control:
---
Private Sub CommandButton1_Click()
Dim oTbl As Table
Dim oCel As Cell
Dim oRng As Range
For Each oTbl In ActiveDocument.Tables
For Each oCel In oTbl.Range.Cells
Set oRng = oCel.Range
oRng.End = oRng.End - 1
Select Case oRng.Text
Case "R"
oCel.Shading.BackgroundPatternColorIndex = wdRed
Case "Y"
oCel.Shading.BackgroundPatternColorIndex = wdYellow
Case "G"
oCel.Shading.BackgroundPatternColorIndex = wdBrightGreen
Case "E"
oCel.Shading.BackgroundPatternColorIndex = wdTurquoise
End Select
Next
Next
End Sub
---
I would like to convert this functionality to work within the C# console
application I mentioned, rather than relying on a user to click and trigger
the functionality. The console app is now running the mail merge
functionality I'm using anyway.
If anyone can assist or point me to a web resource for converting VBA to C#
..NET code, I would really appreciate it.
Regards,
Mike Davis
I have a C# console app that I'm building to automate some Word
functionality. I would like to add code to that app that will conditionally
color some table cell backgrounds based on the text within the cell.
My coding experience is generally limited, especially when trying to convert
from one language to another.
That said, I have the following VBA code that works fine within Word 2003 --
it's assigned to a button control:
---
Private Sub CommandButton1_Click()
Dim oTbl As Table
Dim oCel As Cell
Dim oRng As Range
For Each oTbl In ActiveDocument.Tables
For Each oCel In oTbl.Range.Cells
Set oRng = oCel.Range
oRng.End = oRng.End - 1
Select Case oRng.Text
Case "R"
oCel.Shading.BackgroundPatternColorIndex = wdRed
Case "Y"
oCel.Shading.BackgroundPatternColorIndex = wdYellow
Case "G"
oCel.Shading.BackgroundPatternColorIndex = wdBrightGreen
Case "E"
oCel.Shading.BackgroundPatternColorIndex = wdTurquoise
End Select
Next
Next
End Sub
---
I would like to convert this functionality to work within the C# console
application I mentioned, rather than relying on a user to click and trigger
the functionality. The console app is now running the mail merge
functionality I'm using anyway.
If anyone can assist or point me to a web resource for converting VBA to C#
..NET code, I would really appreciate it.
Regards,
Mike Davis