Results 1 to 10 of 10
  1. #1
    2 Star Lounger
    Join Date
    Mar 2001
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help with macro ? (Word 97)

    Back in Word 6 I had a macro that did this, but then when the newer versions came out, it didn't work anymore, and I've never gotten it to work since. A couple of years ago, someone posted an answer to this, but it didn't work.

    Here's what I'd like to get back:

    a single macro (which I would make an icon for and put it in my toolbar) with 4 functions:
    1) click it and it would change Paragraph | Line Spacing to single
    2) shift-click it and it would change line spacing to solid--so if the text for that paragraph was size 40, the line spacing would be changed to Exactly 40, or if text was size 24, line spacing would change to exactly 24.
    3) control-shift click on the icon to reduce the line spacing by 1 point (exactly 24 down to exactly 23, etc)
    4) control-click on the icon to increase the line spacing by 1 point

    Right now I have 2 separate macros for this, but of the 4 possibilities between them, only 1 works. Here is the macro text that someone sent me earlier to increase-decrease by 1 point (it doesn't work)



    Dim xx
    Dim FP As Object: Set FP = WordBasic.DialogRecord.FormatParagraph(False)
    Dim FF As Object: Set FF = WordBasic.DialogRecord.FormatFont(False)
    WordBasic.CurValues.FormatParagraph FP
    WordBasic.CurValues.FormatFont FF

    Rem *** this section checks if line spacing is set for points,
    Rem *** if not changes it to points ****

    xx = WordBasic.Val(FP.LineSpacing)
    If xx = 0 Then
    xx = WordBasic.Val(FF.Points) * 1.2
    End If

    Rem ***** GetAsyncKeyState(16) checks on status of shift key. If it
    Rem ***** changes, then it toggles from + to -

    If GetAsyncKeyState(16) < 0 Then
    WordBasic.FormatParagraph LineSpacingRule:=4, LineSpacing:=xx - 1
    Else
    WordBasic.FormatParagraph LineSpacingRule:=4, LineSpacing:=xx + 1
    End If
    End Sub

    ===============================================

    Here is the macro to switch from Single Line Spacing to Solid. If the spacing is set to anything other than Single, then clicking this icon DOES set the spacing back to Single. But the part to change to Solid never works.

    Dim xx
    Dim FF As Object: Set FF = WordBasic.DialogRecord.FormatFont(False)
    WordBasic.CurValues.FormatFont FF
    xx = WordBasic.Val(FF.Points)

    If GetAsyncKeyState(16) < 0 Then
    WordBasic.FormatParagraph LineSpacingRule:=0, LineSpacing:=""
    Else
    WordBasic.FormatParagraph LineSpacingRule:=4, LineSpacing:=xx
    End If

    ===================================
    Can anyone spot the errors? and hopefully combine them in to 1 macro

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: help with macro ? (Word 97)

    I don't know how to get the modifier keys working on the button but here is the code (works in Word 2000) that would do these tasks buried in the one macro. It will ask for a number between 1 and 4 and perform the corresponding task.
    <pre>Sub temp1()
    Dim iOption As Integer
    iOption = InputBox("Type the option number that you require.")
    Select Case iOption
    Case "1" 'Set the line spacing to a single line
    Selection.ParagraphFormat.LineSpacingRule = wdLineSpaceSingle

    Case "2" 'Set the line spacing to exactly the font size
    With Selection.ParagraphFormat
    .LineSpacingRule = wdLineSpaceExactly
    .LineSpacing = Selection.Font.Size
    End With

    Case "3" 'Decrease the line spacing by one point
    With Selection.ParagraphFormat
    .LineSpacingRule = wdLineSpaceExactly
    .LineSpacing = .LineSpacing - 1
    End With

    Case "4" 'Increase the line spacing by one point
    With Selection.ParagraphFormat
    .LineSpacingRule = wdLineSpaceExactly
    .LineSpacing = .LineSpacing + 1
    End With
    End Select
    End Sub</pre>

    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    2 Star Lounger
    Join Date
    Mar 2001
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: help with macro ? (Word 97)

    thanks Andrew, that does what I want!

  4. #4
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: help with macro ? (Word 97)

    'Scuse my curiosity, but did you get the modifier keys to work again? And if so, how? 'Cos it sounds like a useful way of reducing the number of buttons needed on a toolbar ... <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    Many thanks
    Beryl M


  5. #5
    2 Star Lounger
    Join Date
    Mar 2001
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: help with macro ? (Word 97)

    The Macro that AL sent me did not include the modifier keys. I'm going to compare one of my other macros in which this DOES work with what he sent me and see if I can figure out how to incorporate them. But I'm no programmer. Do you want me to post the macro I DO have that includes the 4 modifiers to you can look at how it's set up?

  6. #6
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: help with macro ? (Word 97)

    If that's the old macro that worked in your earlier version, then yes, please. I am a programmer (a very junior one!) in VBA so I might be able to work out enough to get it working ... it's worth a try, anyway!

    Many thanks <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    Beryl M


  7. #7
    2 Star Lounger
    Join Date
    Mar 2001
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: help with macro ? (Word 97)

    below is a macro that has 4 different states: normal, shift, control and control-shift. I used it with a custom toolbar button. If I remember right, someone on this lounge wrote this one for me a couple of years back. I don't remember for sure but I think that the Private Declare... line is a necessary part of this macro. If you have other macros, this line must be at the very top of your macro list.


    Private Declare Function GetKeyState Lib "User32" (ByVal nVirtKey As Long) As Long



    Sub IncreaseOrDecreaseSpacing()
    '
    ' IncreaseOrDecreaseSpacing Macro
    ' Macro created 12/04/99 by Jerel Peterson
    '
    Dim Shift As Boolean, Ctrl As Boolean, Alt As Boolean
    If (GetKeyState(16) And 128) = 128 Then
    Shift = True
    Else: Shift = False
    End If
    If (GetKeyState(17) And 128) = 128 Then
    Ctrl = True
    Else: Ctrl = False
    End If
    If (GetKeyState(18) And 128) = 128 Then
    Alt = True
    Else: Alt = False
    End If
    If Ctrl Then
    With Selection.ParagraphFormat
    If Shift Then
    If .SpaceAfter > 3 Then
    .SpaceAfter = .SpaceAfter - 3
    Else: .SpaceAfter = 0
    End If
    Else: .SpaceAfter = .SpaceAfter + 3
    End If
    End With
    Else: With Selection.ParagraphFormat
    If Shift Then
    If .SpaceBefore >= 3 Then
    .SpaceBefore = .SpaceBefore - 3
    Else: .SpaceBefore = 0
    End If
    Else: .SpaceBefore = .SpaceBefore + 3
    End If
    End With
    End If
    WordBasic.PrintStatusBar Selection.ParagraphFormat.SpaceBefore & " pt before, " & Selection.ParagraphFormat.SpaceAfter & " pt after. Use CONTROL for space AFTER, SHIFT to DECREASE space"

    End Sub

  8. #8
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    Willow Grove, Pennsylvania, USA
    Posts
    205
    Thanks
    4
    Thanked 49 Times in 40 Posts

    Re: help with macro ? (Word 97)

    Yes, the GetKeyState function in the Declare statement is an API function, whose code is in User32.dll. The documentation for it is at <A target="_blank" HREF=http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/hh/winui/keybinpt_4z51.asp>http://msdn.microsoft.com/library/default....ybinpt_4z51.asp</A>. The values your macro passes to it are the virtual keycodes for the Shift key (decimal 16 = hex 10), the Ctrl key (decimal 17 = hex 11), and the Alt key (decimal 18 = hex 12). [The "And 128" part is to make sure none of the high-order bits are set.]

    The original WordBasic macro used GetAsyncKeyState, which is similar to GetKeyState; it's documented at <A target="_blank" HREF=http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/hh/winui/keybinpt_1x0l.asp>http://msdn.microsoft.com/library/default....ybinpt_1x0l.asp</A>. To make that macro work, it would need a Declare statement for the API function as well:

    Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal vKey As Long) As Integer

  9. #9
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: help with macro ? (Word 97)

    Well, I dropped this into my VBE, put it on the toolbar as a button, and works fine!

    With nothing pressed, the space before each paragraph increases; with shift, it decreases again; with ctrl the space after the paragraph increases; with ctrl-shift it decreases again.

    You didn't try to use the decrease line spacing options without putting some in first, did you? That would give the effect that they don't work ...

    Thanks for this - it will be very useful to me! <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Beryl M


  10. #10
    2 Star Lounger
    Join Date
    Mar 2001
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: help with macro ? (Word 97)

    The macro that I originally posted is different than this one. This one just increases or decreases spacing before or after paragraph in 3-point increments. The one that doesn't work was supposed to switch to either single spacing or solid leading. I still haven't had time to compare that one with the one Andrew Lockton posted to see where the problem is.

Posting Permissions

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