Home > Software engineering >  AHK: convert text selection to hyperlink with clipboard as target
AHK: convert text selection to hyperlink with clipboard as target

Time:10-31

Using Autohotkey to achieve this behaviour:

  • copy URL from browser
  • select text in word doc
  • press keyboard shortcut
  • AHK converts selected text to hyperlink with clipboard as target.

This is what I have so far:

^b::
wd := ComObjActive("Word.Application")
url := %clipboard%
wd.ActiveDocument.Hyperlinks.Add(wd.Selection.Range, %url%,"","","")
return

I've tried many other variations, but alway get the error that the url variable contains illegal characters.

Any ideas? Thx!

CodePudding user response:

Variable names in an expression are not enclosed in percent signs.

^b::
    wd := ComObjActive("Word.Application")
    url := clipboard
    wd.ActiveDocument.Hyperlinks.Add(wd.Selection.Range, url,"","","")
return

or

^b::
    wd := ComObjActive("Word.Application")
    wd.ActiveDocument.Hyperlinks.Add(wd.Selection.Range, clipboard,"","","")
return
  • Related