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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inset part of text as bold

Status
Not open for further replies.

Dee0612

Technical User
May 2, 2005
17
0
0
GB
I am taking text from Attachmate and putting it onto word. If I have this:

a = TextA
b = TextB
c = TextC

inputtext = a & Chr(13) & b & Chr(13) & c

wrd.ActiveDocument.Fields(1).Select
With wrd.Selection
.InsertAfter Text:=inputtext
End With

I want to have b inserted as bold, is this possible?

thanks
 
1. First of all, it is better to use styles. Generally speaking, the text will be formatted according to the style of the paragraph it is going into.

2. Yes. But it is kind of sloppy. I made the a, b, c into string variables here. I am assuming they are anyway.
Code:
Sub MakeBold()
Dim inputtext As String
Dim a As String
Dim b As String
Dim c As String
Dim oRange As Word.Range
a = "TextA"
b = "TextB"
c = "TextC"

inputtext = a & vbCrLf & b
[COLOR=red]' Why are you selecting this field??
' I can not see a real reason for it[/color red]
ActiveDocument.Fields(1).Select
With Selection
    .InsertAfter Text:=inputtext
[COLOR=red]' OK, collapse and select backwards to pick up b[/color red]
    .Collapse Direction:=wdCollapseEnd
    .MoveStart unit:=wdCharacter, Count:=-Len(b)
[COLOR=red]' set the Range variable for that, = b[/color red]
    Set oRange = Selection.Range
[COLOR=red]' collapse back again and insert c[/color red]
    .Collapse Direction:=wdCollapseEnd
    .InsertAfter Text:=vbCrLf & c
End With
[COLOR=red]' make the range bold and release it[/color red]
    oRange.Font.Bold = True
    Set oRange = Nothing
End Sub

Actually, I am pretty sure there are better ways of doing whatever it is you are doing. Again...why are you selecting the field?

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top