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.
How to change the line interval Topic is solved
How to change the line interval
- Attachments
-
- temp_1019_003.jpg (44.95 KiB) Viewed 680 times
Re: How to change the line interval Topic is solved
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
}
Re: How to change the line interval
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.
Re: How to change the line interval
Code: Select all
#IfWinActive ahk_exe WINWORD.exe
AppsKey::AppsKey
AppsKey & v::ComObjActive("Word.Application").Selection.ParagraphFormat.LineSpacingRule := PLUSHALF := True
#IfWinActive