Greetings,
I am have made an application that opens word documents and removes the
shading patterns from all words. since it will not work on paragraphs i
have to do it per word.
all is working well except when there is a table.
the application start going in each cell word by word and fixes it but
at the end of the row it selects something right outside of the table
(like an extra cell) which throws an exception when i run the code to
remove the shading.

code: (i remove more than just shading)

For Each actualword In Doc.Words
'just for visual help
actualword.Select()
actualword.FormattedText.Font.Color = WdColor.wdColorAutomatic
actualword.HighlightColorIndex = WdColorIndex.wdNoHighlight
actualword.Shading.BackgroundPatternColorIndex =
WdColorIndex.wdNoHighlight
actualword.Shading.ForegroundPatternColorIndex =
WdColorIndex.wdNoHighlight
Next



how can i overcome this ?

thank you

Re: formatting of words in a table throws exception by Helmut

Helmut
Fri Dec 08 20:39:16 CST 2006

Hi Gabriel,

you are encountering problems with the end-of-row mark.

Have a look at this one,
somewhat simplified for ease of testing.
You have selected the end-of-row mark,
if the selection in within a table
and the selection.cells count is zero.

Sub Test45()
Dim rWrd As Range
For Each rWrd In ActiveDocument.Range.Words
'just for visual help
rWrd.Select
If selection.Information(wdWithInTable) = True Then
If selection.Cells.Count = 0 Then
' do nothing
End If
Else
rWrd.FormattedText.Font.Color = WdColor.wdColorAutomatic
rWrd.HighlightColorIndex = WdColorIndex.wdNoHighlight
rWrd.Shading.BackgroundPatternColorIndex _
= WdColorIndex.wdNoHighlight
rWrd.Shading.ForegroundPatternColorIndex _
= WdColorIndex.wdNoHighlight
End If
Next
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Re: formatting of words in a table throws exception by Helmut

Helmut
Fri Dec 08 20:44:45 CST 2006

Hi,

not my day, not my time,

> If selection.Cells.Count = 0 Then
> ' do nothing
> End If

redundant, absolutely useless.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Re: formatting of words in a table throws exception by Helmut

Helmut
Sun Dec 10 03:56:10 CST 2006

Disregard the other two postings.

It may serve as an excuse for coding nonsense,
that Word crashed invariably when testing,
more than a dozen times.

Try to adapt this one to your needs:

Sub Test455()
Dim rWrd As Range
For Each rWrd In ActiveDocument.Range.Words
'just for visual help
rWrd.Select
If selection.Information(wdWithInTable) = True Then
If selection.Cells.Count = 1 Then
rWrd.Font.Color = wdColorRed
' or whatever
End If
Else
rWrd.Font.Color = wdColorRed
' or whatever
End If
Next
End Sub

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Re: formatting of words in a table throws exception by Gabriel

Gabriel
Sun Dec 10 06:17:05 CST 2006

Thank you Helmut so much.

That cells= 1 did the trick ..

in debt ..
Gabriel


Re: formatting of words in a table throws exception by Klaus

Klaus
Mon Dec 11 14:02:23 CST 2006

I put such "do nothing" comment lines all the time in "If ... Then" or
"Select Case" statements...
Just to make it clear what was intended.

Klaus


"Helmut Weber" <nbhymsjxdgcn@mailinator.com> wrote:
> Hi,
>
> not my day, not my time,
>
>> If selection.Cells.Count = 0 Then
>> ' do nothing
>> End If
>
> redundant, absolutely useless.
>
> --
> Greetings from Bavaria, Germany
>
> Helmut Weber, MVP WordVBA
>
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"