-
Notifications
You must be signed in to change notification settings - Fork 71
/
Word_xlComment.ahk
35 lines (34 loc) · 1.45 KB
/
Word_xlComment.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
xlWordComment(text, header="", URL = "", title = ""){
oWord := ComObjActive("Word.Application")
if header <> ; Run only if header isn't empty
{
author := oWord.Application.UserName ; Get current author
oWord.Application.UserName := header ; Set heading as author
}
try ; Trying to add comment
{
oWord.ActiveDocument.Comments.Add(oWord.Selection.Range) ; Add comment
ErrorLevel = 0
}
catch ; Catch errors and display message
{
MsgBox,16, %A_ScriptName%, Comments can only be added in the document's main text. `rCheck the text you have selected and try again.
ErrorLevel = 1
}
if ErrorLevel = 0 ; If comment was added error-free:
{
oWord.Selection.PasteAndFormat(16) ; Paste clipboard data (retains formatting if %text% is from Excel cell)
Send {BackSpace}
if URL <> ; Run only if URL isn't empty
{
oWord.Selection.TypeParagraph ; New line
if title <> ; Run only if title isn't empty
oWord.ActiveDocument.Hyperlinks.Add(oWord.Selection.Range, URL,"","", title) ; Add titled link
Else ; Else use URL as title
oWord.ActiveDocument.Hyperlinks.Add(oWord.Selection.Range, URL,"","", URL) ; Add untitled link
}
if header <> ; Run only if header isn't empty
oWord.Application.UserName := author ; Restore original author
Send {Esc}
}
}