Script to automatically join highlighted text with hyphens?

Get help with using AutoHotkey and its commands and hotkeys
helensmith
Posts: 53
Joined: 12 Oct 2014, 04:27

Script to automatically join highlighted text with hyphens?

12 Oct 2014, 04:33

When I use the mouse to highlight text in MS Word I want to be able to press a hotkey (e.g. F1) and have every word in that highlighted text joined together by a hyphen. As an example if I have some text saying:

The cat sat on the mat

I want it to read:

The-cat-sat-on-the-mat

Does anyone know how I can do this as I am totally lost regarding a script.

Many thanks
Helen
ahcahc
Posts: 110
Joined: 25 Jul 2014, 23:55

Re: Script to automatically join highlighted text with hyphe

12 Oct 2014, 10:51

Code: Select all

F1::
old_clipboard := ClipboardAll
Clipboard=
SendInput, ^c
ClipWait, 1
Clipboard := RegExReplace(clipboard,"(?<=\S) (?=\S)","-")
SendInput, ^v
Sleep, 1
Clipboard := old_clipboard
return
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Script to automatically join highlighted text with hyphe

12 Oct 2014, 10:56

Code: Select all

#IfWinActive, Microsoft Word AHK_CLASS OpusApp	
	
Sc3B::				
Send, ^c
Sleep, 33
SendInput % RegExReplace( Clipboard, " ", "-") 
Return

#IfWinActive
helensmith
Posts: 53
Joined: 12 Oct 2014, 04:27

Re: Script to automatically join highlighted text with hyphe

12 Oct 2014, 17:24

Many thanks for the script it works perfect. Just one more question - do you have any idea how I can have the script automatically set the hyphen colour to white? I know I could set the colour manually in MS Word, however it would be really neat if the script could automatically set the hyphen colour to white.

Many thanks
Helen
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Script to automatically join highlighted text with hyphe

13 Oct 2014, 04:46

In that case, the VBA (Visual Basic for Applications) will be your best friend.
(S)He is a really nice one !!

Good Luck !!

Return to “Ask For Help”

Who is online

Users browsing this forum: barbaque, Bing [Bot], colt, SpikeVanHellsing, vsub and 175 guests