5
votes

Consider the following table in Word 2013

A BBB
A CCC
D E F

A, B and C are merged cells.

A and B are empty. C has text A inside.

Now the following code

Set rng = ActiveDocument.Range(0, 0)  
With rng.Find
    .Forward = True
    .Wrap = wdFindStop
    .Execute "A"
End With

Crashes word on Execute "A".

If I change text to Execute "B" it doesn't find anything but doesn't crash word. Issue is present only in word 2013.

We tried searching manually and Selection.Find cell by cell, but both of those are rather slow.

Is there a quick way to circumvent this error?

EDIT: this is minimum fail example that I constructed. In our application we use a lot of Range.Find, sometimes with wrap and almost never starting from Document.Start

EDIT2: further investigation shows that Error isn't present if you open Document in compatibility mode (Word 97-2003 format).

1
Assuming that you do not have to avoid using Selection.Find in this case, what does the Range.Find version do that, e.g. Selecting the whole document or the Table doesn't do for you? (FWIW I see the error too, and using .Execute2007 also crashes Word).user1379931
what do you expect as an answer? I did also check your problem and it's not working for me as well. Therefore I think it is a simple 'bug' which we are not able to solve. And it seems that you have a solution of using selection.find feature. What is a goal of the bounty you proposed?Kazimierz Jawor
How can A, B & C be merged but A & B are empty? A screen shot would help me understand better, thanks.Automate This
@PortlandRunner Crate table 3x3. Merge two cells in first column, last two cells in second and third rows independently.kilotaras
Here's a possible related issue. They talk about looking at the Windows Event Viewer to find the specific Application error associated with the crash. Even if that issue isn't the same as yours, it might help to look at those logs. You can pull up the event viewer by clicking "Start" ---> "Run", then typing "eventvwr.msc" and hit enter.Blackhawk

1 Answers

1
votes

And you can't just activate a .Find object off the Tables(index).Selection object rather than the range object?

If you are just activating the .Selection object off of the ActiveDocument instead of the Table object then, yeah that could take forever. But coming directly off the table index will speed it up significantly.

ActiveDocument.Tables(1).Select
With Selection.Find
    .Forward = True
    .Wrap = wdFindStop
    .Execute FindText:="A"
End With