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 / March 2008

Tip: Looking for answers? Try searching our database.

How do I search for a Word style without flagging end-of-row marke

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Benjamino5 - 11 Mar 2008 16:43 GMT
I need to search for all styles that are not on a whitelist of approved
styles. When I find an "illegal" style, I need to highlight the text in red.
So far, so good.

The problem is that end-of-row markers in tables get flagged if they have an
illegal style. I want them to be skipped, but I'm not sure how to approach
that. Any ideas?

Here's a code fragment:

___________________________________
' this is part of a loop; "s" is a style; "adoc" is the active document
'
If s.InUse = True And s.Type = 1 And Not IsInList(s.NameLocal, whitelist) Then
                       wd.app.options.DefaultHighlightColorIndex = 6 'wdRed
                       With adoc.range.Find
                           .ClearFormatting()
                           .Text = ""
                           .Style = s.NameLocal
                           .Replacement.Highlight = True
                           .Replacement.Text = ""
                           .Execute(Replace:=2, Format:=True) 'wdReplaceAll
                           If .Found = True Then
                               ' something was found, but it MIGHT be an
end-of-cell marker
                               ' how do I handle it here??

                               ' add the name to the foundList and log
                               ' if it's not in there already
                               If Not foundList.Contains(s.NameLocal + ",")
Then
                                   foundList = foundList + s.NameLocal + ","
                               End If
                           End If
                       End With
                   End If
Benjamino5 - 11 Mar 2008 17:00 GMT
A quick clarification: I'm actually writing in VB.Net, which is why there are
expressions like "foundList.Contains..." and I'm using "style.NameLocal"
instead of just "style."

But the problem I have is strictly a VBA, not VB.Net, problem, so that's why
I'm posting here.

Thanks!
Doug Robbins - Word MVP - 12 Mar 2008 03:59 GMT
You should be able to use the .Information(wdWithinTable) attribute of the
Range object to determine if the range you are dealing with is in a table
and act accordingly.

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

>I need to search for all styles that are not on a whitelist of approved
> styles. When I find an "illegal" style, I need to highlight the text in
[quoted text clipped - 39 lines]
>                        End With
>                    End If
Benjamino5 - 12 Mar 2008 15:55 GMT
Doug,

Once I know the range is inside a table, how can I find out if it's an
end-of-row marker? If it's a regular table cell, I want to highlight the
range as normal--it's only the end-of-row markers themselves I want to avoid
flagging.

Thanks so much for your help--I really appreciate it.

Ben

> You should be able to use the .Information(wdWithinTable) attribute of the
> Range object to determine if the range you are dealing with is in a table
[quoted text clipped - 43 lines]
> >                        End With
> >                    End If
Doug Robbins - Word MVP - 12 Mar 2008 21:04 GMT
When using the .Range of a cell to get its contents, I set the .End of the
range to .End-1 to eliminate the end of cell marker.  So I guess if you set
the .Start of the range to .End - 1, you will probably have the end of cell
marker in the range.

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Doug,
>
[quoted text clipped - 61 lines]
>> >                        End With
>> >                    End If
Benjamino5 - 12 Mar 2008 21:35 GMT
Thanks for your suggestions, Doug! But I was actually trying to find the
end-of-row marker, not the end-of-cell marker.

Maybe it's easier if I explain the big picture of what I'm trying to do:

I'm running a Find. The Find looks for instances of a certain paragraph
style. When it finds them, it highlights them in red.

The problem is that some of those instances of the style are actually just
end-of-row markers; not cells or or end-of-cell markers or even any text at
all; just the spot after the last cell but before the end-of-row marker,
where you can put your cursor, but where you can't type (anything you type
gets dumped into the next row).

I want the code to skip right over those places, and not flag them as having
the style. But I'm not sure how to do that.

Perhaps I'm approaching this the wrong way. But in my code sample below,
when I find something, i.e. when .Found=True, I want to figure out if that
range itself, the found range, is JUST that spot at the end of a row.

Not sure if I'm explaining this well, but any suggestions for how to
approach this would be quite welcome.

Thanks again, Doug!

Ben

> When using the .Range of a cell to get its contents, I set the .End of the
> range to .End-1 to eliminate the end of cell marker.  So I guess if you set
[quoted text clipped - 66 lines]
> >> >                        End With
> >> >                    End If
Doug Robbins - Word MVP - 12 Mar 2008 23:13 GMT
Can you use the Len() of the range.  I imagine that if the found range is
just the end of row marker, it will have a length of (probably) not more
than 1 while the ranges upon which you want to act, would have a length
somewhat greater than that.

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Thanks for your suggestions, Doug! But I was actually trying to find the
> end-of-row marker, not the end-of-cell marker.
[quoted text clipped - 108 lines]
>> >> >                        End With
>> >> >                    End If
Benjamino5 - 12 Mar 2008 23:38 GMT
Doug, I think that could work! I have yet another question, though (thanks
for your patience).

How do I get the range in the first place? I'm not too familiar with the
Find object, but here's my code:

________

If s.InUse = True And s.Type = 1 And Not IsInList(s.NameLocal, whitelist) Then
                       wd.app.options.DefaultHighlightColorIndex = 6 'wdRed
                       With adoc.range.Find
                           .ClearFormatting()
                           .Text = ""
                           .Style = s.NameLocal
                           .Replacement.Highlight = True
                           .Replacement.Text = ""
                           .Execute(Replace:=2, Format:=True) 'wdReplaceAll
                           If .Found = True Then
                               ' I need to check the range here, but how?

                               ' add the name to the foundList and log
                               ' if it's not in there already
                               If Not foundList.Contains(s.NameLocal + ",")
Then
                                   foundList = foundList + s.NameLocal + ","
                               End If
                           End If
                       End With
                   End If

> Can you use the Len() of the range.  I imagine that if the found range is
> just the end of row marker, it will have a length of (probably) not more
> than 1 while the ranges upon which you want to act, would have a length
> somewhat greater than that.
Doug Robbins - Word MVP - 13 Mar 2008 02:44 GMT
This highlights text to which the Heading 1 style has been applied, but does
not highlight the end of row marker even if it has that format.

   Dim myrange As Range
   Selection.HomeKey wdStory
   Selection.Find.ClearFormatting
   Selection.Find.Style = ActiveDocument.Styles("Heading 1")
   With Selection.Find
       Do While .Execute(findText:="", Forward:=True, _
           MatchWildcards:=False, Wrap:=wdFindStop) = True
           Set myrange = Selection.Range
           myrange.HighlightColorIndex = wdRed
           Selection.Collapse wdCollapseEnd
       Loop
   End With

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Doug, I think that could work! I have yet another question, though (thanks
> for your patience).
[quoted text clipped - 35 lines]
>> than 1 while the ranges upon which you want to act, would have a length
>> somewhat greater than that.
fumei - 13 Mar 2008 20:02 GMT
Hi Benjamin05,

"How do I get the range in the first place? I'm not too familiar with the
Find object"

You get the range in the first place by simply using it.  The .Find method of
Range resizes the range itself with every find Found.

IF the found is the end-of-row marker, then you can in fact test for that.

The end-of-row marker is an odd duck and is made up of Chr(13) and Chr(7), in
that order.  Note this is also the same as the end-of-cell marker.

BTW:  I would make a Range object and use the Find on that, rather than adoc.
Range.Find.  Let's say r.

Function IsCellMarker(strIn As String) As Boolean
  If Len(strIn) = 2 And _
       Asc(strIn) = 13 And _
           Asc(Right(strIn, 1)) = 7 Then
     IsCellMarker = True
End Function

Dim r As Range
Set r = adoc.Range
With r.Find
  .....yadda yadda
  Do While .Execute (yadda yadda - BTW: using Do is a better way)
      ' remember r (the Range itself) is actually resized
      If IsCellMarker(r.Text) Then
           ' skip it and continue

>Doug, I think that could work! I have yet another question, though (thanks
>for your patience).
[quoted text clipped - 30 lines]
>> than 1 while the ranges upon which you want to act, would have a length
>> somewhat greater than that.

Rate this thread:






 
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.