-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMSWord_findall.ahk
46 lines (40 loc) · 1.04 KB
/
MSWord_findall.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
36
37
38
39
40
41
42
43
44
45
46
#NoEnv
#SingleInstance Force
FindInAllOpenDocuments() {
global
Try
oWord := ComObjActive("Word.Application")
Catch err
MsgBox, Exception thrown:`n%err%
Search := oWord.Selection.Text
Clipboard := Search
Array := []
loop % oWord.Documents.Count {
If InStr(oWord.documents(A_Index).Range.Text, Search , 1) {
Array.Push(oWord.documents(A_Index).Fullname)
}
}
Gui, New, ,%Search%
For key, val in Array
Gui, Add, Button, Section xm w400 h100 vKno%key% gBtnActive, %val%
Gui, Show
return
BtnActive:
{
SetTitleMatchMode, 2
RegExMatch(A_GuiControl, "\d+$", n) ; Gets button's variable (Kno1, Kno2, etc...), extracts integer and assigns it to 'n'
WordFD_Path := StrSplit(Array[n], ["/", "\"])
WordFD_Path := WordFD_Path[WordFD_Path.Count()]
if WinExist(WordFD_Path)
WinActivate
else
MsgBox, Window not found
oWord.Documents(WordFD_Path).Activate
myFindObject := oWord.Selection.Find
myFindObject.ClearFormatting
myFindObject.Replacement.ClearFormatting
myFindObject.Execute(Search, 1, 0, 0, 0, 0, 1, 1, 0, "", 0, 0, 0, 0, 0)
return
}
return
}