Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2007

Tip: Looking for answers? Try searching our database.

Change formatting for DIFFERENT line's inside a Table cell

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Hemantexec@gmail.com - 07 Apr 2007 16:40 GMT
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
Doug Robbins - Word MVP - 08 Apr 2007 07:57 GMT
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.

Signature

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

> Hey Peoples,
>
[quoted text clipped - 48 lines]
> Cheers,
> Hemant
Hemantexec@gmail.com - 08 Apr 2007 12:25 GMT
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

On Apr 8, 6:57 pm, "Doug Robbins - Word MVP" <d...@REMOVECAPSmvps.org>
wrote:
> Use:
>
[quoted text clipped - 82 lines]
> > Cheers,
> > Hemant
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.