No I meant literal ^p. Word recognizes that as a special sequence meaning paragraph in find/replace. Bookmarks and document variables work much better IMHO. Do not undertake them. ie: setting a document variable is easy as:
oWord.Activedocument.Variables("myVarName").Value = m.lcValue
Bookmark samples:
Re: Copy query to Word Thread #
1169664 Message #
1169912Re: GoTo Bookmark in Word... Thread #
1087963 Message #
1087997Cetin
>I got the code from doing Record Macros, then implementing via VFP. I tried using the bookmarks, but that didn't work with the cr/lf either, so I resorted to more digging. I didn't realize the ^p (I assume you mean Ctrl+P) is what WORD uses as a New Paragraph character... But, it exposed me to other automation stuff, and works... I'll try looking into the ^p later.
>
>Thanks
>
>>I'm lost with this code:) Why not simply ^p for paragraph and execute a replace? I would use document variables or bookmarks. Anyway if it's working for your case then it's correct:)
>>Cetin
>>
>>>Thanks all for the input, after researching, most still did not respect the formatting of the cr/lf... So, I went deeper into the automation and came up with a solution that appears to work each time CORRECTLY...
>>>
>>>After the Word document is loaded, and active document, I was able to process via the following
>>>
>>>lcFind = "{{SOMETHING TO LOOK FOR}}"
>>>lcRep = "Whatever you " + chr(13)+chr(10) + "want to replace with"
>>>
>>>*/ loWord is object pointer to Word application
>>>loWordSel = loWord.Selection
>>>WITH loWordSel.Find
>>> .ClearFormatting()
>>> .Text = lcFind
>>> .Replacement.Text = ""
>>> .Forward = .t.
>>> .Wrap = 1
>>> .Format = .f.
>>> */ The MATCH criteria can really be optional from defaults as needed
>>> .MatchCase = .f.
>>> .MatchWholeWord = .f.
>>> .MatchWildcards = .f.
>>> .MatchSoundsLike = .f.
>>> .MatchAllWordForms = .f.
>>> .Execute()
>>>EndWith
>>>
>>>*/ NOW, break lines on the chr(13) + CHR(10) cr/lf
>>>lnFR = ALINES( laFR, lcRep, .t., CHR(13)+CHR(10))
>>>FOR lnLines = 1 TO lnFR
>>> loWordSel.TypeText( laFR[ lnLines ] )
>>> IF lnLines < lnFR
>>> loWordSel.TypeParagraph()
>>> ENDIF
>>>ENDFOR
>>>
>>>
>>>It appears to work, even with LONG strings beyond the 255 character limit, and by pre-splitting on cr/lf into an array, forcing a TYPEPARAGRAPH() makes it work correctly.
>>>
>>>Thanks again for input, just a stronger solution
>>>
>>>
>>>
>>>
>>>>>Hi all,
>>>>>
>>>>>I'm sure someone has an answer for me here.
>>>>>
>>>>>I have a Word document that I have to do some automation with... So, I have some place-holders in there like {{SOMEFIELD}} where I need to do some inserting of stuff and can successfully do using find/replace automation.
>>>>>
>>>>>Here's the problem. If the text I have has ANY cr/lf (such as a multi-line address), the Word document doesn't properly reflect that, almost like the cr/lf is treated as a non-printable character and doesn't advance to the next line.
>>>>>
>>>>>Am I missing something stupid???
>>>>>
>>>>>Thanks,
>>>>>
>>>>>Don
>>>>
>>>>Don,
>>>>If instead of such placeholders you use document variables or bookmarks then you don't need to do find/replace at all.
>>>>Set document variable's value, or insert into bookmark directly. It'd also be faster than a find/replace.
>>>>
>>>>PS: If you'd use find/replace then you should use special characters for things like line feed (ie: ^p).
>>>>Cetin