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 fair amount about Word, and some DOS (having started with 1.1), but have no idea what GREP is. I suspect it to be a Linux command.
You might have better luck asking about GREP in the Windows forum.
Have you looked at the AutoText feature in Word?
- Eskimo007Mar 06, 2025Copper Contributor
So you reply the same thing to me twice and accuse me of cross-posting (which I didn't do?) Sheesh. Since nobody else with macro knowledge replied to me here, I leave disappointed. Ecept that I found a novel way to identifying all the lines with the string I wanted, which is to open the ascii file in excel, and do its "Find all" which listed all the lines with the string, like I was hoping word's macro language could do. Maybe next time I'll find myself a word macro self-teach online page. Goodbye
- Eskimo007Mar 02, 2025Copper Contributor
Thanks for considering my request Charles. grep is just a linux command to locate a string. the OR vertical bar is a pipe, ie you can in linux use the TYPE command to display the content of a file, the pipe the output to another command, like grep, to basically print the content of a string on your terminal everytime it appears in a file. ie "type <file>|grep <string>" all on one line for example.