text big, text small

O

Osiris

How would I put a BIG text item and a small text item together in a
cell of a table ?
I tried this:

With .Range
.Font.Size = 16
.Text = "tues"

End With
With .Range
.Font.Size = 8
.InsertAfter = "day"

End With

but that just makes "tuesday" 8 points text.
 
J

Jean-Guy Marcil

Osiris was telling us:
Osiris nous racontait que :
How would I put a BIG text item and a small text item together in a
cell of a table ?
I tried this:

With .Range
.Font.Size = 16
.Text = "tues"

End With
With .Range
.Font.Size = 8
.InsertAfter = "day"

End With

but that just makes "tuesday" 8 points text.

We need to see more of your code... what is .Range?
Why two With blocks?

Anyway, you main problem is probably related to the fact that you use
..InsertAfter which includes the previous range as well as the new inserted
text when you are finish executing this code.

Here's is one of many ways of doing this:

'_______________________________________
'To make sure we handle only one cell at the time.
Selection.Range.Collapse wdCollapseStart

'Make sure we are in a table cell
If Not Selection.Information(wdWithInTable) Then
MsgBox "Place the cursor in a table cell."
Exit Sub
End If

With Selection.Cells(1).Range
'remove the cell marker from the range
.Collapse wdCollapseStart
'add "tues" and set size
.Text = "tues"
.Font.Size = 16
'Preapre range to be only" day"
.Collapse wdCollapseEnd
'add "tues" and set size
.Text = "day"
.Font.Size = 8
End With
'_______________________________________

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jay Freedman

You have to point to the different pieces of text before you change
the size. What you've shown (I presume the .Range refers to the range
of some Cell object) just changes the size of the same thing (the
whole cell's range) twice.

Inserting text with VBA doesn't usually work the way it does in the
user interface; you don't "set the size and then start typing". It's
usually better to insert all the text first, then go back and format
it. Try this:

Sub demo()
Dim oCel As Cell
Dim oRg As Range

Set oCel = ActiveDocument.Tables(1).Cell(2, 2)

' point to the whole cell's range
Set oRg = oCel.Range

' put in the text
oRg.Text = "Tuesday"

' point to the first 4 characters
' oRg.Start is already at the start of the cell
oRg.End = oRg.Start + 4

' change its size
oRg.Font.Size = 16

' point to the rest of the text
' exclude the cell marker at the end
oRg.Start = oRg.End
oRg.End = oCel.Range.End - 1

' change its size
oRg.Font.Size = 8
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

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