r_daneel

I am using C# + VSTO to create an application-plugin for Word 2007, and one of my requirements is to find double-lined borders and replace the text in that cell with something. There are also a few other cell border styles that I need to find.

Is there any way to find a cell (or range of cells) in an active word document based on it's border I have not been able to come up with a solution to this yet.

Thanks for your help.


Re: Visual Studio Tools for Office How do I find a cell's border format?

Cindy Meister

There's no way to "find" cell borders. You need to loop through all cells in all tables and check the OutsideLineStyle property. Here's a VBA code snippet to get you started

Dim tbl As Word.Table
Dim cel As Word.Cell

Set tbl = ActiveDocument.Tables(1)
For Each cel In tbl.Range.Cells
If cel.Borders.OutsideLineStyle = wdLineStyleDouble Then
MsgBox cel.Range.Text
End If
Next






Re: Visual Studio Tools for Office How do I find a cell's border format?

r_daneel

Thanks for the snippet. It was pretty easy to convert to C# and it moves through the tables just fine, except it's not matching properly.

Just as an example, this is the kind of table I'm looking at:

Heading 1

Heading 2

Heading 3

Contents 1a

Contents 2a

Contents 3a

Contents 1b

Contents 2b

Contents 3b

Contents 1c

Contents 2c

Contents 3c

Total 1

Total 2

Total 3


In here the double line appears as a bold line near the bottom separating the contents from the total. This is the line in which I am interested. I have checked in the debugger and cell.Borders.OutsideLineStyle has a value of wdLineStyleSingle up to the second-to-last row (ie: contents 1c, contents 2c, contents 3c) where each cell has a OutsideLineStyle value of 999999999.

I wonder if this is because there is more than one line style applied to the cell. That being the case, can I distinguish between cells having the double line at the top of the cell only




Re: Visual Studio Tools for Office How do I find a cell's border format?

r_daneel

Yay! I was able to get something working using the following code:

if (cell.Borders[Word.WdBorderType.wdBorderBottom].LineStyle == Word.WdLineStyle.wdLineStyleDouble) {
MessageBox.Show(cell.Range.Text);
}

Oh, and for the sake of clarity I should point out that I am no longer looking for the double underline above the text I want to find, I am looking for it below it. I imagine the above code would work just fine if I were to swap out wdBorderBottom with wdBorderTop.