Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting Inserted Text

Status
Not open for further replies.

noHandlebars

Technical User
Jun 25, 2008
46
US
I am running a macro that finds a section of text, deletes that section, then inserts new text. The new text needs to be formatted in a special way like horizontally centered and bolded and underlined for specific words. Is there anyway to code the formatting in?

Here's what I have so far:
With ActiveDocument.Content
.Find.Execute FindText:="Section C.3"
TextStart = .Start
.Collapse wdCollapseEnd
.Find.Execute FindText:="Section C.5B:"
.Collapse wdCollapseStart
.Start = TextStart
.Delete
'.InsertBreak wdPageBreak

‘consecutive needs to be underlined and italicized
.InsertAfter "The following consecutive sections from the questionnaire have
been removed because they are not relevant to facility operations:"

‘need blank lines inserted wherever .InsertAfter “” are located
.InsertAfter ""
.InsertAfter ""
.InsertAfter ""

‘all the section headings to be in bold
.InsertAfter "SECTION C.3: UNIT DESIGN RECYCLING/TREATMENT"
.InsertAfter ""

.InsertAfter "SECTION C.4: UNIT DESIGN – THERMAL
TREATMENT/INCINERATOR"
.InsertAfter ""
.InsertAfter "SECTION C.5A: UNIT DESIGN - LANDFILLS"
.InsertParagraphAfter
.Collapse wdCollapseEnd
.InsertBreak wdPageBreak
End With
 
Hi noHandlebars,

You could use a simple Find/Replace operation after your text has been inserted, using:
Find: "consective"
Replace: ^& and sent the font attribute to bold.

The macro recorder will give a pretty good indication of what's required. If there's a risk that "consective" will appear elsewhere in the document, it might be a good idea to insert a dummy string in its place initially (eg .InsertAfter "The following ~!@#$% sections ...) then use:
Find: "~!@#$%"
Replace: "consective" and sent the font attribute to bold.

Cheers

[MS MVP - Word]
 
Is there a special character combination to force a hard return during an .insert
 
You already use the InsertParagraphAfter method, so I quite don't understand your issue.
Anyway you may try to use vbCr or vbLf or vbCrLf

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top