-
Notifications
You must be signed in to change notification settings - Fork 72
/
Word_Comment.ahk
34 lines (33 loc) · 1.25 KB
/
Word_Comment.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
wComment(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
{
oWord.ActiveDocument.Comments.Add(oWord.Selection.Range) ; Add comment
ErrorLevel = 0
}
catch ; Catch errors
{
MsgBox,16, %A_ScriptName%, Something whent wrong. `rCheck the text you have selected and try again.
ErrorLevel = 1
}
if ErrorLevel = 0
{
oWord.Selection.TypeText(text) ; Send text
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}
}
}