'Inserting hyperlink into Word bookmark with AutoHotkey
I have an AutoHotkey script that inserts values into various bookmarks in a Word document.
When inserting a hyperlink (email address), it inserts text. How do I pass it as a hyperlink?
I've read Hyperlinks.Add and tried implementing using the examples but I'm not sure how it translates with AutoHotkey. The examples reference ActiveDocument
.
I'm inserting into a created document versus active document.
Relevant portions of my AutoHotkey script:
FilePath := A_Desktop "\Test\MyWordDoc.docx"
wdApp := ComObjCreate("Word.Application") ; Create an instance of Word.
MyDocNew := wdApp.Documents.Add(FilePath) ; Create a new document.
MyDocNew.Bookmarks("CMname").Range.Text := ManagerName
MyDocNew.Bookmarks("CMphone").Range.Text := ManagerPhone
MyDocNew.Bookmarks("CMemail").Range.Text := ManagerEmail
MyDocNew.ExportAsFixedFormat(A_Desktop "\Notice", 17) ; Export out as a PDF.
MyDocNew.Close(0) ; Close the document without saving.
wdApp.Quit()
I tried variations like
MyDocNew.Hyperlinks.Add(MyDocNew.Bookmarks("CMemail").Range, ManagerEmail)
Solution 1:[1]
It appears that adding .Item
after MyDocNew.Bookmarks
works!
Correct script:
MyDocNew.Hyperlinks.Add(MyDocNew.Bookmarks.Item("CMemail").Range, ManagerEmail)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | jarhead |