Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2006

Tip: Looking for answers? Try searching our database.

formatting of words in a table throws exception

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gabriel - 08 Dec 2006 19:29 GMT
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
Helmut Weber - 09 Dec 2006 02:39 GMT
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

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Helmut Weber - 09 Dec 2006 02:44 GMT
Hi,

not my day, not my time,

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

redundant, absolutely useless.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Klaus Linke - 11 Dec 2006 20:02 GMT
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

> Hi,
>
[quoted text clipped - 5 lines]
>
> redundant, absolutely useless.
Helmut Weber - 10 Dec 2006 09:56 GMT
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

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Gabriel - 10 Dec 2006 12:17 GMT
Thank you Helmut so much.

That cells= 1 did the trick ..

in debt ..
Gabriel
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.