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 / October 2007

Tip: Looking for answers? Try searching our database.

Macro that searches for highlights

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JohnTheTemp - 15 Oct 2007 23:58 GMT
Strange happenings.

I have a macro that searches for highlighting and copies it to the
clipboard. Occasionally, the macro aborts with an error because there's
nothing to copy.

1) If I manually search for highlights, I don't find any.

2) The macro supposedly finds something, but the cursor is still sitting at
the top of the dcoument when the error occurs.

3) I tried to test for a zero-length field to work around the problem, but
the selected data wasn't zero-length. ???? Note #2.

4) I eventually traced the problem to certain cells in a table.

   a) If I delete the data in that cell, the problem persists.

   b) If I select the cells and "remove highlighting" then the macro works
fine.

I know the solution, but I need more..

*  Does anyone know what might be happening?

*  I want to find a way to train my macro to detect the problem and not
abort when it encounters it.

Just in case, here's the relevent portion of the macro (I've test it to see
if it is troubled by those nasty cells -- it is):

Sub temp3()
   Selection.Find.ClearFormatting
   Selection.Find.Highlight = True
   With Selection.Find
       .Text = ""
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindStop
       .Format = True
   End With
   If Selection.Find.Execute = True Then MsgBox "Found"
End Sub

I'm afraid I don't know how to let you examine the cells.

Signature

JohnTheTemp

Helmut Weber - 16 Oct 2007 16:59 GMT
Hi John,

I think that may be the cause of your confusion,
apart from possible other issues.

Select a cell with data,
highlight all of the cell.

Delete the data, the data only(!),
even though you see no highlighting,
the the end-of-cell marker is still highlighted.

MsgBox Selection.Range.HighlightColorIndex

Select the cell, delete, and the highlighting has gone,
or apply no highlighting to the cell.

You may try that in addition:

Sub temp3()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
  .Highlight = True
  While .Execute
     Debug.Print "[" & rDcm.Text & "]"
  Wend
End With
End Sub

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

 
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.