Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Mar 2001
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Some time ago, someone on this forum wrote a macro for me to change letterspacing (Kerning) between letters. If the shift key is held when the macro icon is clicked, the letterspacing is reduced by one point. If the shift key is not held down, then the letterspacing is reduced by 1/4 pt.

    The macro works fine when using the shift key, but when not using the shift key,I have to click the macro button (I put one in the toolbar for this macro) 3 times for it to work once. When using the Shift key, the letterspacing reduces with every click. Could someone check the code and see if they can see why it takes 3 clicks for the 1/4 pt reduction?

    Dim FF As Object
    Dim x
    On Error GoTo -1: On Error GoTo UserCancel
    If WordBasic.SelType() = 2 Then
    Set FF = WordBasic.DialogRecord.FormatFont(False)
    WordBasic.CurValues.FormatFont FF

    If GetAsyncKeyState(16) < 0 Then
    x = WordBasic.Val(FF.Spacing) - 1
    Else
    x = WordBasic.Val(FF.Spacing) - 0.25
    End If
    WordBasic.FormatFont Spacing:=Str(x)
    End If
    UserCancel:

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    Could you post all of the related code?
    This code includes a call to a custom function called "GetAsyncKeyState" - without that function, this snippet of code won't compile or run.

    Just how long ago did someone here write this code? WordBasic was officially replaced by VBA with the advent of Office 97. It's still possible to use WordBasic commands, but with a few exceptions, they've been superseded by VBA - so this code appears to date from around 1996 or earlier. What version of Word are you currently running this in?

    Gary

  3. #3
    2 Star Lounger
    Join Date
    Mar 2001
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Private Declare Function GetAsyncKeyState Lib "User32" (ByVal nVirtKey As Long) As Integer
    Private Declare Function GetKeyState Lib "User32" (ByVal nVirtKey As Long) As Long
    ==========================

    Those 2 lines are at the top of my macro list.

    Yes, these macros are old. Some (maybe most) of my big time-savers go back to the late 90s. I've got 4 or 5 that are very handy that I use to show my computer class how to create macros and customize the toolbar (or ribbon). They all still work except for this little glitch with the shift key on this kerning macro, and one that deals with line spacing that doesn't work at all.

    We just switched from Office 2003 to 2010 this fall. These same macros wouldn't work on 2003, either.

    I'm not a programmer. I've been able to study the ones that people have done for me and been able to modify them or create some simple new ones, but I could never make anything like this from scratch with VBA.

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    It's hard to remember the WordBasic handling of dialogs, but I think this is the VBA equivalent of that code:

    Code:
    Sub ReduceLetterSpacing()
    With Selection
        If .Type = wdSelectionNormal Then
            With .Font
                If GetAsyncKeyState(16) < 0 Then
                    .Spacing = .Spacing - 1
                Else
                    .Spacing = .Spacing - 0.25
                End If
            End With
        End If
    End With
    End Sub

  5. #5
    2 Star Lounger
    Join Date
    Mar 2001
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, it appeared as though that version wasn't working, either. Every third time I ran it, it would condense the type, but the first two times would do nothing. Then it struck me that maybe it WAS working, but the amount was too small to visualize. I zoomed way in on the text, and then it would show movement on every click. If I would have bothered to open up the Font window and look at the spacing settings, I would have seen that it WAS increasing the condensing of the font by .25 pts each time it was clicked.

    So, the old version was working all along, but thanks for giving me the new code. Maybe I can learn a few things from it. Thanks a lot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •