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

Microsoft Word VBA - Setting individual words to BOLD in a table cell

Status
Not open for further replies.

gsdcrazy

Programmer
Sep 2, 2002
31
0
0
US
Gurus,

I am building a Word document with a document template using information in an Access database. I use the "with" structure to define and populate the table cells. In certain cells, I need to BOLD specific words (column information from the Access database) that is concatenated to other columns from the Access database. Is there an "in string" font/bolding command like in Excel? In Excel, I can set selected words in a cell to different fonts/bolding with this:

"&""Arial,Bold""Columbus All-Breed Training Club" & Chr(10) _

Is there anything like that in Word? An excerpt from the code looks like:

If rsTrialEntries("ArmBandNbr") <> 0 Then
.Cells(3).Range.Text = rsTrialEntries("ArmBandNbr")
.Cells(3).Range.Font.Bold = wdToggle
End If
.Cells(4).Range.Text = rsTrialEntries("DogName") _
& " " _
& rsTrialEntries("RegNbr") _

Cell 3 is BOLD and works fine. In Cell 4 I only want to BOLD the "rsTrialEntries("DogName").

Thanks,
gsdcrazy
 
Hi gsdcrazy,

In Word you could do something like the following as you insert the text to be bolded:

With Selection
.EndKey Unit:=wdLine
.Font.Name = "Arial"
.Font.Size = 12
.Font.Bold = True
.TypeText " Text to Insert"
End With

This assumes that all of the piece of text being added requires bolding. Doing so won't affect the attributes of any text already there, but you'll need to switch the bold atttribute off if you then want to add more unbolded text after the bolded text.

Cheers
 
macropod,

This works great! Sorry for the slow response to thank you. I ended up with two "With Selection" statements and the Dog's Name was bolded and the reset of the text in the cell was not. Not ever trying to set up the "With Selection" with the "Set Table . . . With Row" syntax that I use I had to play around a little to get the selection to set correctly, but here is what I ended up with.

Thanks for the great solution.
gsdcrazy

.Cells(4).Select
With Selection
.EndKey Unit:=wdLine
.Font.Name = "Times New Roman"
.Font.Size = 8
.Font.Bold = True
.TypeText rsTrialEntries("DogName")
End With
With Selection
.EndKey Unit:=wdLine
.Font.Name = "Times New Roman"
.Font.Size = 8
.Font.Bold = False
.TypeText " " _
& strRegNbr _
 
Hi gsdcrazy,

You could further simplify your code to:

.Cells(4).Select
With Selection
.EndKey Unit:=wdLine
.Font.Name = "Times New Roman"
.Font.Size = 8
.Font.Bold = True
.TypeText rsTrialEntries("DogName")
.Font.Bold = False
.TypeText " " & strRegNbr
End With

Cheers
 
macropod,

Thanks again. I seem to be doing more with Access for my church and my wife's volunteer groups. This type of formatting makes the documents look so much better.

Your insight really has helped.

gsdcrazy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top