Replace Paragraph char with <p> in Word document

Setup
OS: NT
VB: 6.0
References in VB Project:
1. MS Word 9.0 Object libray
2. OLE Automation
3. VB Runtime objects and procedures
4. VB for applications
5. VB objects and procedures

Problem: I have written a function to replace paragraph char (^p) in word document to <p>. In my system it works fine but in other VB environment it does not work. Functionality is replace and save word doc in text format. I have attached replace method code and portion of the method calling replace method.

Please help me. Thanks in advance

*************

Set objDoc = Application.Documents.Open(FileArray(I), AddToRecentFiles:=False)

replace
   
sNewName = NameWithoutExtension(objDoc.Name)
           
objDoc.SaveAs FileName:=TargetPath & sNewName, FileFormat:=wdFormatTextLineBreaks
        objDoc.Close wdDoNotSaveChanges
        Set objDoc = Nothing

****************

Sub replace()

On Error GoTo err_handle2

    Word.Selection.Find.ClearFormatting
    Word.Selection.Find.Replacement.ClearFormatting
    With Word.Selection.Find
        .Text = "^p"
        .Replacement.Text = "<p></p>^p"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Word.Selection.Find.Execute replace:=wdReplaceAll
    Exit Sub
err_handle2:
End Sub

govinda051198Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tureCommented:
govinda,

Just an untested idea... I suspect the line
  .Wrap = wdFindContinue

Try this instead, and see if it helps:
  .Wrap = wdFindStop

Otherwise, word might keep looping as long as there are paragraph characters in the document, and there will always be some, because they are included in the replacement text.

And... not important, but shouldn't the replacement text be:
  .Replacement.Text = "</p>^p<p>"   ???

Ture Magnusson
Karlstad, Sweden
0
govinda051198Author Commented:
Ture,

I tried, but no luck.

Thanks for considering the question!
0
rasmusj2Commented:
I would suspect that "replace" might be a keyword in the other OS.  Maybe you could rename the Sub replace () to Sub ReplaceParagraphMarks ().  It is certainly worth a try.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tureCommented:
Good thinkin' rasmusj2!

/Ture
0
rasmusj2Commented:
Hope that works!  Or, I will have to keep thinking....
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.