Change formatting for DIFFERENT line's inside a Table cell

H

Hemantexec

Hey Peoples,

I have a table in word , and am trying to change the font size for the
different lines that are in the cell. So for a given cell (say row1,
col3) i want the first line to be font size 16, the next line to be
font size 13.

Anyone know of a way to do this?

My code is alot more complicated than what I've shown here, I've just
tried to keep it to the basics for this problem. All of the places
where there is quotation marks are normally variables.

Sub InsertAddress()

Dim oCell As Cell
Dim oRow As Row
Dim MyRange As Range

For Each oRow In Selection.Tables(1).Rows

For Each oCell In oRow.Cells
oCell.Select
'This code only puts text into every odd numbered coloumn
'code starts
Dim colnum As String
colnum = oCell.ColumnIndex / 2
colnum = Right(colnum, 1)

If colnum = "5" Then 'code ends

'The code in this If trys to put two lines into a cell with the top
line being size 16,
'and the second line being size 13
Selection.Text = "AddressLine1" & vbCrLf
Selection.Font.Size = "16"
MsgBox Selection.Text
With Selection
.InsertAfter ("AddressLine2")
.Font.Size = "13"
End With
MsgBox Selection.Text
End If
Next oCell
Next oRow

End Sub

Any help greatly appreciated,

Cheers,
Hemant
 
D

Doug Robbins - Word MVP

Use:

Dim oTable As Table
Dim i As Long, j As Long

Set oTable = Selection.Tables(1)
With oTable
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count Step 2
With .Cell(i, j).Range
.Text = "AddressLine1" & vbCrLf & "AddressLine2"
.Paragraphs(1).Range.Font.Size = 16
.Paragraphs(2).Range.Font.Size = 13
End With
Next j
Next i
End With

But note that this will insert the words "AddressLine1" and "AddressLine2"
into each of the odd numbered cells on each row. Is that really what you
want.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
H

Hemantexec

Thanks HEAPS for your help, this is exactly what i need.

I'll probably be finished in the next 24 hours or so, and i'll post my
exact code so you can see why i needed this,.

Thanks again.

Hemant
 

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