Macro that searches for highlights

J

JohnTheTemp

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.
 
H

Helmut Weber

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

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

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