I apologize, this should be simple. I don't expect it to be more than 4-5 lines.
I need a script for Microsoft Word. When F1 is pressed, then the document moves to the table of contents. When F2 is pressed, the document searches for "Hello World" and moves to it. Basically, I am positioning to common locations inside an active word document.
I have been working at this for a while. I finally give up and need to ask the community...
F1::
oWord := ComObjActive("Word.Application")
oRange := oWord.ActiveDocument.range().find
oRange.clearformatting()
oRange.Wrap:=1
oRange.Execute("Table Of Contents")
Return
F2::
oWord := ComObjActive("Word.Application")
oRange := oWord.ActiveDocument.range().find
oRange.clearformatting()
oRange.Wrap:=1
oRange.Execute("Hello World")
Return
Microsoft Word Active Document GoTo some text...
-
- Posts: 2
- Joined: 27 Sep 2018, 17:20
-
- Posts: 2
- Joined: 27 Sep 2018, 17:20
Re: Microsoft Word Active Document GoTo some text...
I seem to have found a method that works:
oWord := ComObjActive("Word.Application")
oWord.ActiveWindow.Selection.Find.ClearFormatting
oWord.ActiveWindow.Selection.Find.Text := "TOC"
oWord.ActiveWindow.Selection.Find.Wrap := 1 ; wdFindContinue
oWord.ActiveWindow.Selection.Find.Execute("Table Of Contents")
Return
oWord := ComObjActive("Word.Application")
oWord.ActiveWindow.Selection.Find.ClearFormatting
oWord.ActiveWindow.Selection.Find.Text := "TOC"
oWord.ActiveWindow.Selection.Find.Wrap := 1 ; wdFindContinue
oWord.ActiveWindow.Selection.Find.Execute("Table Of Contents")
Return
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: Microsoft Word Active Document GoTo some text...
It can be done in one line like this:Architect123 wrote:I seem to have found a method that works:
oWord := ComObjActive("Word.Application")
oWord.ActiveWindow.Selection.Find.ClearFormatting
oWord.ActiveWindow.Selection.Find.Text := "TOC"
oWord.ActiveWindow.Selection.Find.Wrap := 1 ; wdFindContinue
oWord.ActiveWindow.Selection.Find.Execute("Table Of Contents")
Return
Code: Select all
ComObjActive("Word.Application").Selection.Find.Execute("Table Of Contents",,,,,,,1)
If you want to do it more in line with your code, there is some redundancy.
Code: Select all
oWord := ComObjActive("Word.Application")
oWord.Selection.Find.ClearFormatting
oWord.Selection.Find.Text := "Table Of Contents"
oWord.Selection.Find.Wrap := 1 ; wdFindContinue
oWord.Selection.Find.Execute
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks