Hard enter value from VB6 into Word

R

Richard Cole

Hi

This may well be the wrong newsgroup, but hopefully you can point me to the
correct group if it is.

I've got a VB6 program that generates Word 2003 documents from templates.

The VB6 program uses a piece of code that loops through a program built
array and replaces the Variable name (Col 0 in the array) (which is already
in the template) with the replacement value (Col 1 in the array). This all
works fine. This is happening all in VB6 using Word.Application object
..Selection.Find.Execute Replace:=wdReplaceAll command in a loop for each
non-blank entry in the array.

with WrdApp
... Some code to control loop and set ActivePane Views
With .Selection.Find
.Text = ReplacementList(I, 0)
.Replacement.Text = ReplacementList(I, 1)
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
' Replace all occurrences
.Selection.Find.Execute Replace:=wdReplaceAll
end with

But... When I need to replace a variable with multiple paragraphs, I am
creating ReplacementList (x,1) using the predefined vbCr (or Chr$(13)) as
my paragraph breaker
(i.e
ReplacementList (x,0) = "##VariableToReplace##"
ReplacementList (x,0) = "Sentence 1" & vbCr & "Sentence 2"
), but this is generates a 'Soft Enter' (like Shift + Enter), so is not
creating new lines correctly in bulleted or number lists and when in a
style with a defined spacing before each paragraph, the inter-paragraph
spacing is being lost.

I've tried using the predefined vbCrLf (vbCr & vbLf) but this just puts in
an unrecognised character box.

I need to know the ASCII value of the 'Hard Enter' (what would be ^p in a
Word search replace), so that I can get these document formatted correctly.

Many thanks in advance.

Richard
 
D

Doug Robbins - Word MVP

vbCr will insert a hard return. Your issue is that the formatting/Style
applied to the text that is being replaced is being lost. You will need to
include some code to re-apply it.

--
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, originally posted via msnews.microsoft.com
 
R

Richard Cole

vbCr will insert a hard return. Your issue is that the formatting/Style
applied to the text that is being replaced is being lost. You will need to
include some code to re-apply it.

Doug

I thought that too, but all of the styles used are set to continue in the
same style in the next paragraph.

If I open a new document based on one of the templates, in Word, and press
Enter, then the same style is applied and it does what I want. If I
shift+Enter then it does what I am seeing from the code.
If I copy the replacement value to the clipboard (in VB6 IDE), go into
Word, select the replacement text then paste from the clipboard, this works
as I want it to.

Playing at home, I notice that in Word Replace (Ctrl+H) I can't enter a
multi paragraph replacement value, although if I enter the replacement
value as "This is a multi^pparagraph" it does put in a hard Enter for the
^p, so I may try replacing all of the vbCr's with "^p" when I get back to
work on Monday and see if this works OK.

Thanks

Richard
 

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