Need to add to code

D

Dave Neve

Hi

The code below is for marking a word in Thai so that it is easier to
remember the 'tone' and vowel length.

eg. tha,thoop

Sub FallingLong()

Dim wordrange As Range, lrange As Range, i As Long, j As Long
Set wordrange = Selection.Range
j = 2
For i = 1 To wordrange.Characters.Count
Set lrange = wordrange.Characters(i)
lrange.Font.Size = 16
lrange.Font.Size = lrange.Font.Size - j
j = j + 2
lrange.Font.Spacing = 5
wordrange.Font.Color = wdColorSkyBlue
Next i
End Sub


But as you can see, there is a problem.

If the word has lots of characters, the final ones are too small to see
unless you have the vision of an owl!!!

I realise that I need a way of counting the characters in a word and an
'if, then' statement
but I am still incapble of writing this (sorry)

Could sm at least give me the outline and I will try to incorporte it into
my macros.

Thanks in advance
 
M

macropod

Hi Dave,

Perhaps something like:

Sub FallingLong()
Dim wordrange As Range, lrange As Range, i As Long, j As Long
Set wordrange = Selection.Range
For i = 1 To wordrange.Characters.Count
Set lrange = wordrange.Characters(i)
lrange.Font.Size = 16 - Int(24.5 * i / wordrange.Characters.Count)/2
lrange.Font.Spacing = 5
wordrange.Font.Color = wdColorSkyBlue
Next i
End Sub

This way, your font size will decrease in 0.5pt units, but will never
decrease below 4pt. The shorter your text string, the faster the rate of
decrease, and vice-versa.

Cheers
 
D

Dave Neve

Hi

Thanks for this code which does what you say, namely that the font doesn't
drop down below 4.

However, 4 is already too small for my old eyes.

I know I promised to try to manipulate the code myself but I am at a loss as
to how the changed bit works.

Could you take me through

lrange.Font.Size = 16 - Int(24.5 * i /
wordrange.Characters.Count)/2

Really grateful if you could explain this line to me.

Thanks
 
M

macropod

Hi Dave,

The '16' simply sets the upper font size.

The 'Int' function returns on the whole-number result of the calculation
within the brackets.

The '/2' divides the result of the Int function by 2, which allows for the
fact that fonts can be set in 1/2pt increments. Thus, we're subtracting a
1/2pt at a time from the 16pt starting position.

The '24.5' is basically 12pts*2+0.5pt, and controls the lower limit of your
final point sizes.

Finally, the ' i / wordrange.Characters.Count' is just the current character
number (i) divided by the character count. This resturns a fraction that
gets deducted from the 24.5.

Thus, every so often 'Int(24.5-i / wordrange.Characters.Count)/2' updates
and a new font size is calculated. If you need a larger 'final' font, simply
decrease the '24' by 2 for every 1pt increase.

Cheers

Dave Neve said:
Hi

Thanks for this code which does what you say, namely that the font doesn't
drop down below 4.

However, 4 is already too small for my old eyes.

I know I promised to try to manipulate the code myself but I am at a loss as
to how the changed bit works.

Could you take me through

lrange.Font.Size = 16 - Int(24.5 * i /
wordrange.Characters.Count)/2

Really grateful if you could explain this line to me.

Thanks
 

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