Help with code

  • Thread starter Thread starter Flicc
  • Start date Start date
F

Flicc

Hello,

I just started an internship, and for my internship i'm making word
templates, with some basic VB code. It should work in the following
way: employees when opening the file get an wizzard with fields to
fill in and the rest is drawn from a database. Everything works fine,
except for when i want the output of a wizzard to start on a new
line.

The code for the wizzard:

Selection.Find.ClearFormatting
With Selection.Find
.Text = _
"uur per week, de werktijden zijn van"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:= _
"FILLIN ""werktijden"" ", _
PreserveFormatting:=True

--------------------
The count:=2 is gives 2 spaces behind the word i searched for, however
i dont want to just fill in enough spaces till we start on a new line,
since this should ofcourse be possible with vb code. I'm really a noob
in this area, so pls explain on a for dummies level :)

Thanks in advance!
 
Hello, Flicc,

If you want to insert a paragraph, you can use:

Selection.TypeParagraph

If you want a line break instead of a new paragraph, try inserting a
vertical tab within the text. Something like:

Selection.TypeText "text before break" Text:=Chr(11) & "text after"

BTW. In general you may find it helpful to record a macro while you
manually perform the desired operation. I generally don't find these
recorded macros to be directly useful, but they quickly provide a good
idea about how to accomplish the task you want to accomplish.

Groetjes,
Randy
 
Hello, Flicc,

Sorry, what I meant was:

Selection.TypeText Text:="text before break" & Chr(11) & "text after"

Groetjes,
Randy
 
Back
Top