Hi,
if anybody finds it handy to search a string with simple selecting it an
press a key, here is the macro (best used with F3 shortcut):
-- snip --
Option Explicit
' (C) 2003 Theodor Willax
' DISCLAIMER:
'
' This software is provided "as is", without any guarantee made as to its
' suitability or fitness for any particular use. It may contain bugs, so
use of
' this tool is at your own risk. The author takes no responsibility for any
' damage whatsoever that may be caused through its use.
'
' FindNextSelected():
' If there is any text selected in the ActiveDocument the next occurence
of this
' string is searched and selected. If EndOfDocument is reached, the search
' starts at the beginning of the ActiveDocument and selects the next
occurence
' of the search string, if the user wants to.
' If no text in the ActiveDocument is selected, nothing is done.
' It is best used with a shortcut to F3 key.
Sub FindNextSelected()
If ActiveWindow.type <> "Text" Then
MsgBox sInfoTextFile
Exit Sub
End If
Dim sSelected, currLine, currCol
sSelected = ActiveDocument.Selection
If sSelected = "" Then
Exit Sub
End If
currLine = ActiveDocument.Selection.CurrentLine
currCol = ActiveDocument.Selection.CurrentColumn
ActiveDocument.Selection.FindText sSelected, dsMatchCase
' If we are at the end of the document, start search at the beginning,
' if the user wants to.
If currLine = ActiveDocument.Selection.CurrentLine _
And currCol = ActiveDocument.Selection.CurrentColumn Then
Dim answer
answer = MsgBox(sQuestionContinue, vbYesNo + vbQuestion, sQuestionTitle)
If answer = vbNo Then
Exit Sub
End If
ActiveDocument.Selection.StartOfDocument
ActiveDocument.Selection.FindText sSelected, dsMatchCase
End If
End Sub
Dim sInfoTextFile, sQuestionContinue, sQuestionTitle
sInfoTextFile = "This macro can only be run when a text editor window
is active."
sQuestionContinue = "Search has reached the end of document." + vbCrLf + _
"Do you want to continue searching from the beginning?"
sQuestionTitle = "Find Next Selected"
-- snap --
Simply safe the code in an .vbs file and add it to your macros. Select
shortcut F3 to execute it. Have fun.
Regards, Theo