A
avkokin
Hello.
In my last post I asked about building list of entries words with
number of page where these words was detected. With your help I wrote
next code (below). But I have one important question:
Is it possible somehow optimize this macro? How? Thank you for any
ideas.
Sincerely, Anton
Sub poisk()
Dim a As String, b As String
Do
Selection.HomeKey wdStory
b = InputBox("Input the word in to the field:", "Search entries of
words")
b = tInput(b)
If b = "Press button CANCEL" Then
Exit Do
End If
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = b
.Forward = True
.Wrap = wdFindStop
.Execute
End With
While Selection.Find.Execute = True
a = a & CStr(Selection.Information(wdActiveEndPageNumber)) &
vbCr
Wend
If Not b = "" Then
With Selection
.EndKey Unit:=wdStory
.InsertAfter vbCr & vbCr
.Collapse wdCollapseEnd
.TypeText a
End With
End If
Loop Until b <> ""
End Sub
Function tInput(b As String) As String
If StrPtr(b) = 0 Then
tInput = "Press button CANCEL"
Else
If b = "" Then
tInput = ""
MsgBox "Input the word!"
Else
tInput = b
End If
End If
End Function
In my last post I asked about building list of entries words with
number of page where these words was detected. With your help I wrote
next code (below). But I have one important question:
Is it possible somehow optimize this macro? How? Thank you for any
ideas.
Sincerely, Anton
Sub poisk()
Dim a As String, b As String
Do
Selection.HomeKey wdStory
b = InputBox("Input the word in to the field:", "Search entries of
words")
b = tInput(b)
If b = "Press button CANCEL" Then
Exit Do
End If
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = b
.Forward = True
.Wrap = wdFindStop
.Execute
End With
While Selection.Find.Execute = True
a = a & CStr(Selection.Information(wdActiveEndPageNumber)) &
vbCr
Wend
If Not b = "" Then
With Selection
.EndKey Unit:=wdStory
.InsertAfter vbCr & vbCr
.Collapse wdCollapseEnd
.TypeText a
End With
End If
Loop Until b <> ""
End Sub
Function tInput(b As String) As String
If StrPtr(b) = 0 Then
tInput = "Press button CANCEL"
Else
If b = "" Then
tInput = ""
MsgBox "Input the word!"
Else
tInput = b
End If
End If
End Function