PDA

View Full Version : Solved: Format part of each cell's text in a table



TechNet
08-29-2005, 07:47 AM
Hi guys,

Thank you so much for all your support. Now Xpress became part of my work.

I have some problem here. I have a word document with one table (rows 4 and columns 2 with no header row). Each cell has its contents like

example:

Description

Name: xyz
DOB: 09/09/99
abc: def
Not all the cells are having same information but will be seperated by a colon ":", so I need to bold the portion before colon. Here in this example, I have to bold "Name", "DOB" etc... Not all cells are having Name, DOB they could have any thing. Could you please help me out in this situation. I have to write a macro.

Thanks a lot in advance
TechNet

TonyJollans
08-29-2005, 09:20 AM
Do it with a Find and Replace.

Check "Use wildcards"
Find "<[!^13:]{1,}:" (without the quotes)
Replace with Bold formatting

fumei
08-29-2005, 09:54 AM
Hi TechNet, you should WRITE your steps out, then you could easily see the steps that actually need to be done.

Sub makeBold()
Dim oCell As Word.Cell
Dim oPara As Word.Paragraph
Dim var
Dim oRange As Word.Range
' for each cell in table 1
For Each oCell In ActiveDocument.Tables(1).Range.Cells
' if cell HAS text
If oCell.Range.Text <> "" Then
' check if text has a ":"
For Each oPara In oCell.Range.Paragraphs
var = InStr(1, oPara.Range.Text, ":")
' if text DOES have a ":"
If var > 0 Then
' set a range for the cell range
' then collapse the range backwards
' until you hit the ":"
Set oRange = oPara.Range
oRange.MoveEndUntil cset:=":", Count:=wdBackward
' bold THAT range
oRange.Font.Bold = True
' go to next paragraph in cell
Set oRange = Nothing
End If
' repeat check for ":"
Next
End If
' go to next cell
Next
End Sub

TechNet
08-29-2005, 11:38 AM
Hi Gerry,
You are really great! Thank you so much, I got it.
Regards
TechNet