Word macro with unix grep like function

N

Nimmi Srivastav

Hi,

I would appreciate if someone could help me with an MSWORD macro that
does the following:
(1) Prompts the user to enter a search string
(2) Searches all occurrences of the specified string in the active
document
(3) Dumps all lines containing the specified string in a new window
(line being defined as a string of characters that ends with ^p)

Thanks in advance,
Nimmi
 
G

Graham Mayor

How about

Dim Source As Document
Dim Target As Document
Dim oPara As Paragraph
Dim sText As String
Dim oRng As Range
Set Source = ActiveDocument
Set Target = Documents.Add
sText = InputBox("Enter string")
For Each oPara In Source.Range.Paragraphs
If InStr(1, oPara.Range, sText) Then
Target.Range.InsertAfter oPara.Range
End If
Next oPara

http://www.gmayor.com/installing_macro.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
N

nimmi_srivastav

How about

Dim Source As Document
Dim Target As Document
Dim oPara As Paragraph
Dim sText As String
Dim oRng As Range
Set Source = ActiveDocument
Set Target = Documents.Add
sText = InputBox("Enter string")
For Each oPara In Source.Range.Paragraphs
    If InStr(1, oPara.Range, sText) Then
        Target.Range.InsertAfter oPara.Range
    End If
Next oPara

http://www.gmayor.com/installing_macro.htm

--

Works like a charm.....

Thanks - NS
 
G

Graham Mayor

You are welcome :)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

How about

Dim Source As Document
Dim Target As Document
Dim oPara As Paragraph
Dim sText As String
Dim oRng As Range
Set Source = ActiveDocument
Set Target = Documents.Add
sText = InputBox("Enter string")
For Each oPara In Source.Range.Paragraphs
If InStr(1, oPara.Range, sText) Then
Target.Range.InsertAfter oPara.Range
End If
Next oPara

http://www.gmayor.com/installing_macro.htm

--

Works like a charm.....

Thanks - NS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top