Forum Discussion
Need a macro to create a subdocument
- Mar 08, 2025
Use a macro containing the following code
Sub MakeSubDoc()
Dim source As Document
Dim target As Document
Dim str As String
Dim rngstr As Range
Set source = ActiveDocument
Set target = Documents.Add
source.Activate
str = InputBox("Insert the text to be found.")
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:=str, MatchWildcards:=False, MatchCase:=True, Wrap:=wdFindStop, Forward:=True) = True
Set rngstr = Selection.Range.Bookmarks("\line")
target.Range.InsertAfter rngstr & vbCr
Selection.Collapse wdCollapseEnd
Loop
End With
target.Activate
End Sub
...or maybe I can chain some DOS commands ala "type myfile.vcf|grep "@hotmail.com" >hotmaillines.txt... (Where can I find a grep program for DOS?)
- Charles_KenyonMar 06, 2025Bronze Contributor
Sorry. I know Word. I know DOS to some extent.
I know not GREP.
You might ask in a Windows forum.
Have you looked at the AutoText feature in Word?