How to change the line interval Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hancre
Posts: 248
Joined: 02 Jul 2021, 20:51

How to change the line interval

Post by hancre » 19 Oct 2021, 06:43

I want to change the line interval in ms-word by AutoHotkey.

How can I get the result?
I can't find the results in google.
Attachments
temp_1019_003.jpg
temp_1019_003.jpg (44.95 KiB) Viewed 663 times

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: How to change the line interval  Topic is solved

Post by mikeyww » 19 Oct 2021, 07:22

Code: Select all

#IfWinActive ahk_exe WINWORD.exe
F3:: ; F3 = Change line spacing to 1.5
wordLineSpacing(1.5)
SoundBeep, 1700
Return
#IfWinActive

wordLineSpacing(spacing, pointsLines := "") {
 /* Set line spacing in Microsoft Word ------------------
 https://www.autohotkey.com/boards/viewtopic.php?p=231071
 https://www.autohotkey.com/boards/viewtopic.php?p=425817#p425817
 https://docs.microsoft.com/en-us/office/vba/api/word.wdlinespacing
 wdLineSpaceSingle   = 0 ; Single spaced (default)
 wdLineSpace1pt5     = 1 ; Space-and-a-half line spacing (current font size plus 6 points)
 wdLineSpaceDouble   = 2 ; Double-spaced
 wdLineSpaceAtLeast  = 3 ; Minimum points required
 wdLineSpaceExactly  = 4 ; Maximum points required (often uses less space than single spacing)
 wdLineSpaceMultiple = 5 ; Number of lines indicated
 First parameter (spacing) can be "min", "max", "mult", or a number to indicate the number of lines (e.g., 2.5)
 Spacing of 1, 1.5, and 2 uses standard options as noted above; other numbers will use multi-line spacing option
 For "min" and "max", second parameter is number of POINTS; for "mult", second parameter is number of LINES
 --------------------------------------------------------
 */
 Static wdLineSpace := {1: 0, 1.5: 1, 2: 2, min: 3, max: 4, mult: 5}         ; Map spacing parameter to wdLineSpace
 If !WinExist("ahk_exe WINWORD.exe")                                         ; If Microsoft Word is not open,
  Return                                                                     ;  then complete this function;
 oWord := ComObjActive("Word.Application")                                   ;  otherwise, use open Word document
 If !wdLineSpace.HasKey(spacing)                                             ; If no key, spacing is no. of lines,
  pointsLines := spacing, spacing := "mult"                                  ;  so adjust for multi-line spacing
 points := spacing = "mult" ? oWord.LinesToPoints(pointsLines) : pointsLines ; If multi-line, convert lines to pts
 Try oWord.Selection.ParagraphFormat.LineSpacingRule := wdLineSpace[spacing] ; Set spacing according to key
 Try oWord.Selection.ParagraphFormat.LineSpacing     := points               ; Apply points to line spacing
}

hancre
Posts: 248
Joined: 02 Jul 2021, 20:51

Re: How to change the line interval

Post by hancre » 23 Oct 2021, 01:39

mikeyww wrote:
19 Oct 2021, 07:22
Thanks a lot for your help. It works well.

If I use the fixed value(1.5) for the line interval, can I trim the code?

I tried this following code. But it doesn't work.

Code: Select all

Appskey & v:: ; Change line spacing to 1.5
wordLineSpacing(1.5)
Return


How can i fix the issue?
Thanks for any help in advance.

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: How to change the line interval

Post by mikeyww » 23 Oct 2021, 05:52

Code: Select all

#IfWinActive ahk_exe WINWORD.exe
AppsKey::AppsKey
AppsKey & v::ComObjActive("Word.Application").Selection.ParagraphFormat.LineSpacingRule := PLUSHALF := True
#IfWinActive

Post Reply

Return to “Ask for Help (v1)”