How can I just change the text background colour using VBA?

B

Blackberry

Hi All

Developing a VB6 app that writes text and a bit of formatting to a table in
a MS Word template doc via VBA.

I can change the text colour, bold, italic and underline params fine on my
text, but I can't get the background colour of my text to change.

Formatting the bg colour for a whole cell in a table is no good to me and
I've just found that the paragraph format is also no good, as I need to
format the bg colour of text on a line by line basis. For example cell 1
might look like the following:

Fred Bloggs < bg colour needs to be blue
Bilbo Bloggs <bg colour needs to be untouched, ie white
Barry Bloggs <bg colour needs to be red
etc

Move onto next cell.

The code that I am currently using is:

oNewDoc.Tables(1).Cell(intRow,
intCol).Range.Paragraphs(intLine).Range.ParagraphFormat.Shading.BackgroundPatternColor
= wdColorRed

Which doesn't really work because if cell 1 has 2 names in it then cell 4
with one name has 2 lines of the same colour. I need 1 line of colour that
covers just the name.

I've noticed that the highlight option might do it, but you appear to be
limited to 15 or so colours (with most being too dark). Am I wrong?

I'd prefer some form of TextFormat.Shading etc format as it opens the
colours up for me, but there doesn't seem to be an option.

Note I have to work with Office 2000/2003 users.

Thanks
 
J

Jean-Guy Marcil

Blackberry was telling us:
Blackberry nous racontait que :
Hi All

Developing a VB6 app that writes text and a bit of formatting to a
table in a MS Word template doc via VBA.

I can change the text colour, bold, italic and underline params fine
on my text, but I can't get the background colour of my text to
change.

Formatting the bg colour for a whole cell in a table is no good to me
and I've just found that the paragraph format is also no good, as I
need to format the bg colour of text on a line by line basis. For
example cell 1 might look like the following:

Fred Bloggs < bg colour needs to be blue
Bilbo Bloggs <bg colour needs to be untouched, ie white
Barry Bloggs <bg colour needs to be red
etc

Move onto next cell.

The code that I am currently using is:

oNewDoc.Tables(1).Cell(intRow,
intCol).Range.Paragraphs(intLine).Range.ParagraphFormat.Shading.BackgroundPatternColor
= wdColorRed

Which doesn't really work because if cell 1 has 2 names in it then
cell 4 with one name has 2 lines of the same colour. I need 1 line
of colour that covers just the name.

I do not understand the problem as you state it here.
Can you explain that paragraph again please?
Maybe posting a sample of the text you are dealing with?


--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
S

Shauna Kelly

Hi Blackberry

I suggest using character styles that have been defined to have the shading
you want. If you apply the styles to a .Range, then the shading will be
applied only to the text, and not to the whole paragraph.

Here's some code to get you going. To test it out, create a document with a
table and put some text in each cell of the table.

Sub FormatBloggs()

Dim oNewDoc As Word.Document

Dim sBlueStyle As String
Dim sWhiteStyle As String
Dim sRedStyle As String

Dim styBlue As Word.Style
Dim styWhite As Word.Style
Dim styRed As Word.Style

Dim oTable As Word.Table
Dim nRowCounter As Long
Dim nColCounter As Long

'Get a reference to our document
Set oNewDoc = ActiveDocument

'Establish the names of our styles
sBlueStyle = "Blue"
sWhiteStyle = "White"
sRedStyle = "Red"

On Error Resume Next
'If necessary, create new styles in our document
With oNewDoc.Styles
.Add Name:=sBlueStyle, Type:=wdStyleTypeCharacter '
wdStyleTypeParagraph
.Add Name:=sWhiteStyle, Type:=wdStyleTypeCharacter '
wdStyleTypeParagraph
.Add Name:=sRedStyle, Type:=wdStyleTypeCharacter
'wdStyleTypeParagraph
End With

On Error GoTo 0

'Get a reference to our styles
With oNewDoc.Styles
Set styBlue = .Item(sBlueStyle)
Set styWhite = .Item(sWhiteStyle)
Set styRed = .Item(sRedStyle)

End With

'Identify the shading we want for our styles
With styBlue.Font.Shading
.Texture = wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = wdColorBlue
End With

With styWhite.Font.Shading
.Texture = wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = wdColorWhite
End With

With styRed.Font.Shading
.Texture = wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = wdColorRed
End With

On Error Resume Next

'Apply the character styles to text in our table
Set oTable = oNewDoc.Tables(1)

For nRowCounter = 1 To oTable.Rows.Count
For nColCounter = 1 To oTable.Columns.Count
oTable.Cell(nRowCounter,
nColCounter).Range.Paragraphs(1).Range.Style = styBlue
oTable.Cell(nRowCounter,
nColCounter).Range.Paragraphs(2).Range.Style = styWhite
oTable.Cell(nRowCounter,
nColCounter).Range.Paragraphs(3).Range.Style = styRed
Next nColCounter
Next nRowCounter

End Sub


I'd suggest that (a) you'll need to add appropriate error checking and (b)
use names for the styles that reflect function, not format. Blue, White and
Red are not good names!

Hope this helps.

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

Blackberry

Hi All

Thanks for your feedback.

Been trying things out before you kindly sent me the below and went with the
highlight colour option, but what I can't understand is that even though I'm
selecting the 2nd paragraph to initiate my highlighting it still covers all
paragraphs!!!

To explain I have a cell in my table consisting of the following:

BilboBaggins <vbCrLf>
Freddie Boggs<vbCfLf>

When I firstly format BilboBaggins it works perfectly I get the colour bg
that I want, but when I format Freddie Boggs the bg colour for both is
changed to what it should be for Freddie Boggs even though my code quite
clearly calls the 2nd paragraph, eg:

Set oDoc = oNewDoc.Tables(1).Cell(intRow, intCol).Range.Paragraphs(2)

oDoc.Range.Text = arrPupilData(0, intCurrentRec)

With oDoc.Range
.Font.Color = wdBlack
.HighlightColorIndex = wdRed
.Font.Italic = False
.Font.Bold = False
.Font.Underline = False
End With

Surely the above should only format the Freddie Boggs text??

Another thing is that I use the following line at the end:

oDoc.Range.Text = oDoc.Range.Text & vbCrLf

but instead of this just putting one paragraph/carriage return marker after
the name, eg Freddie Boggs, it puts 2 markers!

If I use .Doc.Range.InsertParagraphAfter instead of the above it puts the
right markers in, but crashes on any cells with more than 1 name in it - how
frustrating is this!!!!!

Any ideas?






Hi Blackberry

I suggest using character styles that have been defined to have the shading
you want. If you apply the styles to a .Range, then the shading will be
applied only to the text, and not to the whole paragraph.

Here's some code to get you going. To test it out, create a document with a
table and put some text in each cell of the table.

Sub FormatBloggs()

Dim oNewDoc As Word.Document

Dim sBlueStyle As String
Dim sWhiteStyle As String
Dim sRedStyle As String

Dim styBlue As Word.Style
Dim styWhite As Word.Style
Dim styRed As Word.Style

Dim oTable As Word.Table
Dim nRowCounter As Long
Dim nColCounter As Long

'Get a reference to our document
Set oNewDoc = ActiveDocument

'Establish the names of our styles
sBlueStyle = "Blue"
sWhiteStyle = "White"
sRedStyle = "Red"

On Error Resume Next
'If necessary, create new styles in our document
With oNewDoc.Styles
.Add Name:=sBlueStyle, Type:=wdStyleTypeCharacter '
wdStyleTypeParagraph
.Add Name:=sWhiteStyle, Type:=wdStyleTypeCharacter '
wdStyleTypeParagraph
.Add Name:=sRedStyle, Type:=wdStyleTypeCharacter
'wdStyleTypeParagraph
End With

On Error GoTo 0

'Get a reference to our styles
With oNewDoc.Styles
Set styBlue = .Item(sBlueStyle)
Set styWhite = .Item(sWhiteStyle)
Set styRed = .Item(sRedStyle)

End With

'Identify the shading we want for our styles
With styBlue.Font.Shading
.Texture = wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = wdColorBlue
End With

With styWhite.Font.Shading
.Texture = wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = wdColorWhite
End With

With styRed.Font.Shading
.Texture = wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = wdColorRed
End With

On Error Resume Next

'Apply the character styles to text in our table
Set oTable = oNewDoc.Tables(1)

For nRowCounter = 1 To oTable.Rows.Count
For nColCounter = 1 To oTable.Columns.Count
oTable.Cell(nRowCounter,
nColCounter).Range.Paragraphs(1).Range.Style = styBlue
oTable.Cell(nRowCounter,
nColCounter).Range.Paragraphs(2).Range.Style = styWhite
oTable.Cell(nRowCounter,
nColCounter).Range.Paragraphs(3).Range.Style = styRed
Next nColCounter
Next nRowCounter

End Sub


I'd suggest that (a) you'll need to add appropriate error checking and (b)
use names for the styles that reflect function, not format. Blue, White and
Red are not good names!

Hope this helps.

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

Blackberry

Hi Shauna

Many thanks for the code you sent me. Looks like a life saver!

Just to expand on this, could I pre-save the styles into my Word templates
and just call them when I need them?

Just thinking if this would save processor time as I have around 20 styles
to create.

Do I also need to format the text in these styles as the font sizes and the
like where a bit manic!

Hi All

Thanks for your feedback.

Been trying things out before you kindly sent me the below and went with the
highlight colour option, but what I can't understand is that even though I'm
selecting the 2nd paragraph to initiate my highlighting it still covers all
paragraphs!!!

To explain I have a cell in my table consisting of the following:

BilboBaggins <vbCrLf>
Freddie Boggs<vbCfLf>

When I firstly format BilboBaggins it works perfectly I get the colour bg
that I want, but when I format Freddie Boggs the bg colour for both is
changed to what it should be for Freddie Boggs even though my code quite
clearly calls the 2nd paragraph, eg:

Set oDoc = oNewDoc.Tables(1).Cell(intRow, intCol).Range.Paragraphs(2)

oDoc.Range.Text = arrPupilData(0, intCurrentRec)

With oDoc.Range
.Font.Color = wdBlack
.HighlightColorIndex = wdRed
.Font.Italic = False
.Font.Bold = False
.Font.Underline = False
End With

Surely the above should only format the Freddie Boggs text??

Another thing is that I use the following line at the end:

oDoc.Range.Text = oDoc.Range.Text & vbCrLf

but instead of this just putting one paragraph/carriage return marker after
the name, eg Freddie Boggs, it puts 2 markers!

If I use .Doc.Range.InsertParagraphAfter instead of the above it puts the
right markers in, but crashes on any cells with more than 1 name in it - how
frustrating is this!!!!!

Any ideas?






Hi Blackberry

I suggest using character styles that have been defined to have the shading
you want. If you apply the styles to a .Range, then the shading will be
applied only to the text, and not to the whole paragraph.

Here's some code to get you going. To test it out, create a document with a
table and put some text in each cell of the table.

Sub FormatBloggs()

Dim oNewDoc As Word.Document

Dim sBlueStyle As String
Dim sWhiteStyle As String
Dim sRedStyle As String

Dim styBlue As Word.Style
Dim styWhite As Word.Style
Dim styRed As Word.Style

Dim oTable As Word.Table
Dim nRowCounter As Long
Dim nColCounter As Long

'Get a reference to our document
Set oNewDoc = ActiveDocument

'Establish the names of our styles
sBlueStyle = "Blue"
sWhiteStyle = "White"
sRedStyle = "Red"

On Error Resume Next
'If necessary, create new styles in our document
With oNewDoc.Styles
.Add Name:=sBlueStyle, Type:=wdStyleTypeCharacter '
wdStyleTypeParagraph
.Add Name:=sWhiteStyle, Type:=wdStyleTypeCharacter '
wdStyleTypeParagraph
.Add Name:=sRedStyle, Type:=wdStyleTypeCharacter
'wdStyleTypeParagraph
End With

On Error GoTo 0

'Get a reference to our styles
With oNewDoc.Styles
Set styBlue = .Item(sBlueStyle)
Set styWhite = .Item(sWhiteStyle)
Set styRed = .Item(sRedStyle)

End With

'Identify the shading we want for our styles
With styBlue.Font.Shading
.Texture = wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = wdColorBlue
End With

With styWhite.Font.Shading
.Texture = wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = wdColorWhite
End With

With styRed.Font.Shading
.Texture = wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = wdColorRed
End With

On Error Resume Next

'Apply the character styles to text in our table
Set oTable = oNewDoc.Tables(1)

For nRowCounter = 1 To oTable.Rows.Count
For nColCounter = 1 To oTable.Columns.Count
oTable.Cell(nRowCounter,
nColCounter).Range.Paragraphs(1).Range.Style = styBlue
oTable.Cell(nRowCounter,
nColCounter).Range.Paragraphs(2).Range.Style = styWhite
oTable.Cell(nRowCounter,
nColCounter).Range.Paragraphs(3).Range.Style = styRed
Next nColCounter
Next nRowCounter

End Sub


I'd suggest that (a) you'll need to add appropriate error checking and (b)
use names for the styles that reflect function, not format. Blue, White and
Red are not good names!

Hope this helps.

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

Robert Morley

Hi Blackberry,

Just FYI, the groups...

microsoft.public.vb.enterprise and
microsoft.public.vb.general.discussion

....are definitely the wrong groups for Word VBA questions, and most people there won't know the answers to your question. Those
groups are for VB6 and below. I see you've also posted to a couple of Word VBA groups and gotten some responses. Those are the
correct place.


Rob
 
J

Jean-Guy Marcil

Blackberry was telling us:
Blackberry nous racontait que :
Hi All

Thanks for your feedback.

Been trying things out before you kindly sent me the below and went
with the highlight colour option, but what I can't understand is that
even though I'm selecting the 2nd paragraph to initiate my
highlighting it still covers all paragraphs!!!

To explain I have a cell in my table consisting of the following:

BilboBaggins <vbCrLf>
Freddie Boggs<vbCfLf>

When I firstly format BilboBaggins it works perfectly I get the
colour bg that I want, but when I format Freddie Boggs the bg colour
for both is changed to what it should be for Freddie Boggs even
though my code quite clearly calls the 2nd paragraph, eg:

Set oDoc = oNewDoc.Tables(1).Cell(intRow, intCol).Range.Paragraphs(2)

oDoc.Range.Text = arrPupilData(0, intCurrentRec)

With oDoc.Range
.Font.Color = wdBlack
.HighlightColorIndex = wdRed
.Font.Italic = False
.Font.Bold = False
.Font.Underline = False
End With

Surely the above should only format the Freddie Boggs text??

Please, next time paint a full picture, it will be easier for all involved!
I guessed from looking at your code that you are actually dynamically
inserting paragraphs in your table and formatting them as you go along.

Now, the line
Set oDoc = oNewDoc.Tables(1).Cell(intRow, intCol).Range.Paragraphs(2)
is probably used after you have inserted the first name.
Before it gets executed, I guess that the content of the cell is:
|------------------|
| BilboBaggins¶ |
|¤ |
|------------------|

If that is the case, it means that when the line above gets executed, it
sets oDoc to the cell marker (¤). So, when you next execute
oDoc.Range.Text = arrPupilData(0, intCurrentRec)
to insert the Freddie Boggs paragraph, the cell marker cannot be replaced by
that text as a cell marker cannot be deleted. In effect, that line inserts
the paragraph before the cell marker, but oDoc still points to the cell
marker. Finally, when you get into
With oDoc.Range
oDoc points to the cell marker, which means that all the subsequent changes
are applied to the cell marker, i.e. the whole cell.
Another thing is that I use the following line at the end:

oDoc.Range.Text = oDoc.Range.Text & vbCrLf

What is oDoc.Range when it gets executed?
Have you debugged the code to see what is happening?
but instead of this just putting one paragraph/carriage return marker
after the name, eg Freddie Boggs, it puts 2 markers!

If I use .Doc.Range.InsertParagraphAfter instead of the above it puts
the right markers in, but crashes on any cells with more than 1 name
in it - how frustrating is this!!!!!

Any ideas?

When dealing with cells and VBA, you have to be aware that the cell marker
maybe part of a range or selection. A cell marker is counted as a paragraph,
but it is very different from other paragraphs (It cannot be deleted, if you
format it, you format the whole cell, etc.).
Make sure that your code does not include the cell marker, unless this is
what you want.

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
B

Blackberry

Apologies Jean-Guy

I didn't want to be too wordy in case it frightened people away.

Yes, I keep an ongoing count of the paragraphs used in each cell so
Paragraphs(2) is actually shown as Paragraphs(intLine) in my code.

I have done a msgbox what is my range.text value and it did show a funny
square at the end of the text. Sounds like this is my issue how can I omit
the marker from my formatting??

Thanks

Blackberry was telling us:
Blackberry nous racontait que :
Hi All

Thanks for your feedback.

Been trying things out before you kindly sent me the below and went
with the highlight colour option, but what I can't understand is that
even though I'm selecting the 2nd paragraph to initiate my
highlighting it still covers all paragraphs!!!

To explain I have a cell in my table consisting of the following:

BilboBaggins <vbCrLf>
Freddie Boggs<vbCfLf>

When I firstly format BilboBaggins it works perfectly I get the
colour bg that I want, but when I format Freddie Boggs the bg colour
for both is changed to what it should be for Freddie Boggs even
though my code quite clearly calls the 2nd paragraph, eg:

Set oDoc = oNewDoc.Tables(1).Cell(intRow, intCol).Range.Paragraphs(2)

oDoc.Range.Text = arrPupilData(0, intCurrentRec)

With oDoc.Range
.Font.Color = wdBlack
.HighlightColorIndex = wdRed
.Font.Italic = False
.Font.Bold = False
.Font.Underline = False
End With

Surely the above should only format the Freddie Boggs text??

Please, next time paint a full picture, it will be easier for all involved!
I guessed from looking at your code that you are actually dynamically
inserting paragraphs in your table and formatting them as you go along.

Now, the line
Set oDoc = oNewDoc.Tables(1).Cell(intRow, intCol).Range.Paragraphs(2)
is probably used after you have inserted the first name.
Before it gets executed, I guess that the content of the cell is:
|------------------|
| BilboBaggins¶ |
|¤ |
|------------------|

If that is the case, it means that when the line above gets executed, it
sets oDoc to the cell marker (¤). So, when you next execute
oDoc.Range.Text = arrPupilData(0, intCurrentRec)
to insert the Freddie Boggs paragraph, the cell marker cannot be replaced by
that text as a cell marker cannot be deleted. In effect, that line inserts
the paragraph before the cell marker, but oDoc still points to the cell
marker. Finally, when you get into
With oDoc.Range
oDoc points to the cell marker, which means that all the subsequent changes
are applied to the cell marker, i.e. the whole cell.
Another thing is that I use the following line at the end:

oDoc.Range.Text = oDoc.Range.Text & vbCrLf

What is oDoc.Range when it gets executed?
Have you debugged the code to see what is happening?
but instead of this just putting one paragraph/carriage return marker
after the name, eg Freddie Boggs, it puts 2 markers!

If I use .Doc.Range.InsertParagraphAfter instead of the above it puts
the right markers in, but crashes on any cells with more than 1 name
in it - how frustrating is this!!!!!

Any ideas?

When dealing with cells and VBA, you have to be aware that the cell marker
maybe part of a range or selection. A cell marker is counted as a paragraph,
but it is very different from other paragraphs (It cannot be deleted, if you
format it, you format the whole cell, etc.).
Make sure that your code does not include the cell marker, unless this is
what you want.

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jean-Guy Marcil

Blackberry was telling us:
Blackberry nous racontait que :
Apologies Jean-Guy

I didn't want to be too wordy in case it frightened people away.

Yes, I keep an ongoing count of the paragraphs used in each cell so
Paragraphs(2) is actually shown as Paragraphs(intLine) in my code.

I have done a msgbox what is my range.text value and it did show a
funny square at the end of the text. Sounds like this is my issue
how can I omit the marker from my formatting??

Since you are really working with ranges, use a range object, no a paragraph
one. Try this to get you going:

'_______________________________________
Dim rgePara As Range

'This picks up the cell marker: ¤
Set rgePara = ActiveDocument.Tables(1).Cell(1, 1).Range.Paragraphs(2).Range

With rgePara
'Remove cell marker from range
.Collapse wdCollapseStart
.Text = "Freddie Boggs" & vbCrLf
.Font.Color = wdBlack
.HighlightColorIndex = wdRed
.Font.Italic = False
.Font.Bold = False
.Font.Underline = False
End With
'_______________________________________

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
S

Shauna Kelly

Hi

Yes, you can put the styles in the template and format them to your heart's
content. Make sure you create *character* styles - not paragraph styles.
Character styles will only format individual characters, which is, from my
understanding, what you need.
Do I also need to format the text in these styles as the font sizes and
the
like where a bit manic!

Sounds like all (some?) of the text in your template has been formatted with
direct formatting. That's not good.

You should not have to change the font settings for the character style if
you want everything about the text to be the same as the surrounding text
except the shading. A character style by default takes on the font
formatting of the underlying paragraph style that has been applied to the
text. You could change the font settings for the character style, but all
you would be doing is creating layer upon layer of direct formatting. This
makes it hard to see what's going on, hard to edit, and makes for
unnecessarily large files.

Open (a copy of) your template, do ctrl-a to select all the text, then
ctrl-q and ctrl-spacebar. That will take out all direct formatting. Now,
modify the styles you use to give you the formatting you want.

Make sure you really work through the information Jean-Guy gave you about
end-of-cell markers. That's where most of your problems lie.

Hope this helps.

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

Blackberry

Hi Shauna

Would you say it makes operations considerably faster if the stylesheets are
already in the template rather than being created at runtime?

Having watched the Word doc at work it looks like Anti-virus packages kick
in with their scans at the add stylesheets stage, but funnily enough leave
the rest of the code alone!

Thanks

Hi

Yes, you can put the styles in the template and format them to your heart's
content. Make sure you create *character* styles - not paragraph styles.
Character styles will only format individual characters, which is, from my
understanding, what you need.
Do I also need to format the text in these styles as the font sizes and
the
like where a bit manic!

Sounds like all (some?) of the text in your template has been formatted with
direct formatting. That's not good.

You should not have to change the font settings for the character style if
you want everything about the text to be the same as the surrounding text
except the shading. A character style by default takes on the font
formatting of the underlying paragraph style that has been applied to the
text. You could change the font settings for the character style, but all
you would be doing is creating layer upon layer of direct formatting. This
makes it hard to see what's going on, hard to edit, and makes for
unnecessarily large files.

Open (a copy of) your template, do ctrl-a to select all the text, then
ctrl-q and ctrl-spacebar. That will take out all direct formatting. Now,
modify the styles you use to give you the formatting you want.

Make sure you really work through the information Jean-Guy gave you about
end-of-cell markers. That's where most of your problems lie.

Hope this helps.

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

Blackberry

Many thanks everybody

Really appreciated.

Rgds BBerry

Blackberry was telling us:
Blackberry nous racontait que :
Apologies Jean-Guy

I didn't want to be too wordy in case it frightened people away.

Yes, I keep an ongoing count of the paragraphs used in each cell so
Paragraphs(2) is actually shown as Paragraphs(intLine) in my code.

I have done a msgbox what is my range.text value and it did show a
funny square at the end of the text. Sounds like this is my issue
how can I omit the marker from my formatting??

Since you are really working with ranges, use a range object, no a paragraph
one. Try this to get you going:

'_______________________________________
Dim rgePara As Range

'This picks up the cell marker: ¤
Set rgePara = ActiveDocument.Tables(1).Cell(1, 1).Range.Paragraphs(2).Range

With rgePara
'Remove cell marker from range
.Collapse wdCollapseStart
.Text = "Freddie Boggs" & vbCrLf
.Font.Color = wdBlack
.HighlightColorIndex = wdRed
.Font.Italic = False
.Font.Bold = False
.Font.Underline = False
End With
'_______________________________________

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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