Getting rid of comment style

S

Stephen English

I have a table to which I am ading a row.
Because the previous last row has a Comment Reference style, it is carrying
over to the new row.
I think this code should fix but it doesn't want to!
With tblIndex
.Rows.Add
Set rngIndex = .Cell(.Rows.Count, 1).Range
With rngIndex
.Style = "Table Text"
.Text = strTemp
End With
End With
Any ideas please?
Stephen
 
S

Shauna Kelly

Hi Stephen

The problem here is that the Comment Reference style is a character style.
And Table Text is (I assume) a paragraph style.

If Comment Reference hasn't been changed from the default of 8pt, you can
see the effect if you modify Table Text to be, say, 11pt text in a strange
colour (pink, red, whatever) and run your code. You'll see that the new row
has the colour property from Table Text and the font size property of
Comment Reference.

That's because Word layers character styles over paragraph styles.

So you need to reset the .Font of the range. While you're there, you may as
well reset the .ParagraphFormat as well, just in case.

This should work:

Dim tblIndex As Word.Table
Dim rngIndex As Word.Range
Dim strTemp As String

strTemp = "Hello world"

Set tblIndex = ActiveDocument.Tables(1)

With tblIndex
.Rows.Add
Set rngIndex = .Cell(.Rows.Count, 1).Range
With rngIndex
.Font.Reset
.ParagraphFormat.Reset
.Style = "Table Text"
.Text = strTemp
End With
End With

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top