Word 2007 Find Problem

M

Mike McNeill

I have developed a macro which uses the Find.Execute method to locate a
string with 2 x paragraph symbols (^p). e.g. "MAN" & "^p^p"

This worked fine in pre-2007 days, but now with 2007, hangs the macro in a
loop - it is in a Do...While loop, searching the Content range and should
continue after the loop if no result.

I tried this in Word by hand and sure enough it was replicated there so it's
probably not the macro environment that causes it.

Any ideas anyone? I'm in early days of the Office 2007 world and not
enjoying it so far (-:
Mike
 
D

Doug Robbins - Word MVP

Show us the code.

--
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
 
S

StevenM

To: Mike,

Instead of using "Find," take a look at the following code:

Sub TestFindInRange()
Dim oRange As Range
Set oRange = ActiveDocument.Range
Set oRange = FindInRange(oRange, "MAN" & vbCr & vbCr)
oRange.Select
End Sub

Function FindInRange(ByVal oRange As Range, sStr As String) As Range
Dim nPos As Long

nPos = InStr(oRange.Text, sStr)
If nPos > 0 Then
oRange.End = oRange.Start + nPos - 1
oRange.Collapse wdCollapseEnd
oRange.End = oRange.Start + Len(sStr)
Set FindInRange = oRange
Else
Set FindInRange = Nothing
End If
End Function

Steven Craig Miller
 
M

Mike McNeill

Here is the (relevant part of) code Doug -
"search_ManParts" is initially set to "MAN"

.....
With srchRange
'find extra para mark
Set srchRange = new_Doc.Content
Do While .Find.Execute(finDtext:=search_ManParts & "^p^p", _
MatchCase:=False, MatchWholeWord:=True, Forward:=True, _
ReplaceWith:=(search_ManParts & "^p")) = True
'reset search range
.SetRange .End, new_Doc.Content.End
Loop
End With
.....

This has been taken from the Find/Replace function dialogue box in Word

I have in the meantime found that it can work ...
The macro firstly converts and opens a Plain Text file and then runs the
Find routine. This is when it hangs.
If I use a .doc or .docx file the Find function does work OK. So it is
something to do with the more sophisticated file format!

Incidently Steven Miller's suggestion of using vbCr instead of ^p does work
with all document formats, so that looks like the best solution - I don't
know why I didn't think of that!!!
Weird that it was OK in 97-2003

Thanks for your interest and help Doug and Steven
Cheers - Mike
 
D

Doug Robbins - Word MVP

Why don't you just use a Wildcard Replace to replace (MAN)^13^13 with \1^p

--
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
 
M

Mike McNeill

Yes - that works as well Doug
I assume ^13 is the same code as CRLF from the ASCII table.
I have tried the vbCr trick in the macro and that works and has fixed the
hanging problem. I suppose there are many ways of writing the same thing,
but some work and some don't!!

Thanks again for your help

By the way, I have posted a question about Graphics file conversion for
importing HPGL format files into 2007, but haven't had any reply. It is in
NG: "microsoft.public.word.general"
Do you know anything about how 2007 deals with image file import/inserts? A
special 3rd party Hpglim32.flt file worked fine with Office 97-2003 but
doesn't work at all with 2007!!
Any suggestions gratefully received.

Mike
 
D

Doug Robbins - Word MVP

The microsoft.public.word.general newsgroup was removed from the msnews.com
newsgroup servers more than 10 years ago, but lives on "courtesy" of some
ISP servers who "slurp" from the source newsgroups.

You should therefore post your question to the
microsoft.public.word.drawing.graphics newsgroup.

I do not know the answer.
--
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
 
M

Mike McNeill

Thanks for the good news Doug and for your previous help
..
I have been there and already had an answer to the HPGL problem from Bob
Buckland. v helpful.
See my post reply on 5 June if you need to know the full story (-: Basically
it's not possible anymore.

Mike
 

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