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
I know a lot about Word. I know some things about DOS. I know nothing about GREP. I suspect it to be a Linux program.
In DOS (or actually the Windows command line) you can use Batch files with the .bat extension to run a list of DOS commands.
I think we have been corresponding in another forum as well. If I am correct, I ask you to look at A Message to Forum Cross-Posters.