A family of Microsoft word processing software products for creating web, email, and print documents.
You seem determined to keep the name of the output file a secret. Assuming it's 'TARGET FILE', try:
Sub Demo()
Application.ScreenUpdating = False
Dim strFnd As String, DocSrc As Document, DocTgt As Document, i As Long
Const StrTgt As String = "TARGET FILE"
strFnd = Trim(UCase(InputBox("Category to Find?")))
If strFnd = "" Then Exit Sub
Set DocSrc = ActiveDocument
For i = 1 To Documents.Count
If Split(Documents(i).Name, ".doc")(0) = StrTgt Then
Set DocTgt = Documents(i): Exit For
End If
Next
If DocTgt Is Nothing Then
MsgBox StrTgt & " is not open", vbInformation
Set DocSrc = Nothing: Exit Sub
End If
If DocTgt.Name = DocSrc.Name Then
MsgBox StrTgt & " is the same as the source document!", vbExclamation
Set DocSrc = Nothing: Set DocTgt = Nothing: Exit Sub
End If
With DocSrc.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "[!^13]@^13[!^13]@^13CATEGORY : \*^13\*^13\*^13\*^13\*^13\*^13"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = True
.Execute
End With
Do While .Find.Found
If UCase(Trim(Split(Split(Split(.Text, "CATEGORY : ")(1), vbCr)(0), " ")(0))) = strFnd Then
DocTgt.Characters.Last.Text = .Text & vbCr
End If
.Collapse wdCollapseEnd
.Find.Execute
Loop
End With
Set DocSrc = Nothing: Set DocTgt = Nothing
Application.ScreenUpdating = True
End Sub