Formating Strings with Color etc...

A

Al & Cay Grant

Hi Folks,

I have a string which is made of other strings during a loop
using multiple & string connectors.

Their is a nested loop depending on how many selections
are made in a listbox so that if two selections are made you might
end up with something like;

line1
line2
line3

line1
line2
line3

etc.....

These strings all endup being in one variable which is then inserted into
a document.

When in the document each string needs to have the following added so
that it looks like;

Act: line1
Section: line2
Penalty: line3

Act: line1
Section: line2
Penalty: line3

etc....

I could add the Act/Section/Penalty in during the loop stage but I want
to add font formating to the Act/Section/Penalty.

Does anyone know the easiest way to do this? I suspect I need to
use a table?

Cheers

- AL
 
H

Helmut Weber

Hi Al,
how about something like that:
Dim sStr As String
Dim oRng As Range
Set oRng = Selection.Range
sStr = "Prg1 Whatever" & Chr$(13) & "Prg2 Whatever" _
& Chr$(13) & "Prg3 Whatever" & Chr$(13)
oRng.Text = sStr
oRng.End = oRng.Start + Len(sStr)
oRng.Font.Bold = True
oRng.Font.ColorIndex = wdRed
Of course, here not the string itself is formatted,
which is hardly possible, as far as i know,
but the text that results form the string insertion.
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, NT 4.0
 
A

Al & Cay Grant

I am not sure if I was quite clear. Of

Act: Line1
Penalty: Line2
Section: Line 2

I only want the words: "Act" "Penalty" and "Section" to be formatted wdRed!!

Makes things a little more tricky eh?

- Al
 
H

Helmut Weber

Hi Al & Cay,
Dim sStr As String
Dim oRng As Range
Dim iEnd As Integer
Dim iCnt As Integer ' acounter
Dim sArr(3) As String
sArr(1) = "Act:"
sArr(2) = "Penalty:"
sArr(3) = "Section:"
Set oRng = Selection.Range
sStr = "Act: Line1" & Chr$(13) & "Penalty: Line2" _
& Chr$(13) & "Section: Line 3" & Chr$(13)
oRng.Text = sStr
iEnd = oRng.End
For iCnt = 1 To 3
With oRng.Find
.Text = sArr(iCnt)
.Execute
oRng.Font.Bold = True
oRng.Font.ColorIndex = wdRed
oRng.Start = oRng.End
oRng.End = iEnd
End With
Next
I've omitted things like clearformatting and other
gotchas like .find.options for simplicity.
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, NT 4.0
 

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