Font.Spacing error

C

Clive Tolley

See comments for problems encountered in the following code.
s2 is Single returned from selecting a space within the overall selection to
be acted on, and reading its font.spacing, and s3 = s2 before any changes are
made to s2. Problems are found when this is (correctly) read as -0.65
Is the problem derived from manipulation of minus numbers? It is rather
difficult to program when incorrect values are returned by the program. Or
what am I missing here?

' Replaces spacing of spaces in selection with new spacing
Call ClearFormat
With Selection.Find
.Text = " "
.Font.Spacing = s2 ' But Font.Spacing is here returned as -0.6
.Replacement.Text = "^&"
' The following complicated line (used also previously in code)
attempts to prevent more than one decimal place being assigned to the
font.spacing amount. However, the font.spacing is still at -0.65!
.Replacement.Font.Spacing = 0 - Fix(10 * (Selection.Font.Size /
b2)) / 10
.Wrap = wdFindStop
.Execute
' The following code is because VBA does not return the correct
values;
' the returned numbers here are still not correct, but it seems to
work.
' Word has a particular predilection for -0.65 as a reduction,
even when
' it has not been called for or determined by the program.
If .Found = False Then

If s2 <= s3 - 0.05 Then
s2 = s3 + 0.05
GoTo 50
End If

If s2 >= s3 + 0.05 Then GoTo CollSel

s2 = s2 - 0.05
GoTo 50

End If

Do While .Found = True
.Execute Replace:=wdReplaceOne
rngOriginalSelection.Select
Loop

End With
 
K

Klaus Linke

Hi Clive,

It's probably some weird internal rounding error.

Officially, ".Spacing" is a Single, but only multiples of 0.05 seem to be
allowed.
Word "rounds" -.65 to -.6, and -.7 to -.65.
But OTOH, it "rounds" -.55 to -.55, and -.6 to -.6.

No idea what the "logic" behind that rounding is, but once you know the problem,
it shouldn't be hard to work around it.
Something like
..Font.Spacing = s2 -.01
should do the trick and force Word to always round the same way.

Regards,
Klaus
 

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