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 / January 2005

Tip: Looking for answers? Try searching our database.

Font.Spacing error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Clive Tolley - 24 Jan 2005 01:23 GMT
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
Klaus Linke - 24 Jan 2005 18:16 GMT
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

> See comments for problems encountered in the following code.
> s2 is Single returned from selecting a space within the overall selection
[quoted text clipped - 44 lines]
>
>         End With
 
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.