Snowshoestu
11-29-2011, 01:53 PM
I was trying to merge to "found" strings of code to Find a string and then extract those pages to a new Document. I have the following but it isn't working correctly. Any suggestions would be appreciated.
Sub New_Doc()
Dim sWord As String
sWord = InputBox("Enter term to find", "Print pages")
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
While .Execute(findText:=sWord)
Selection.Extend
Application.Browser.Next
' copies selected page
Selection.Copy
' creates a new document and saves it
Documents.Add DocumentType:=wdNewBlankDocument
Selection.PasteAndFormat (wdPasteDefault)
ActiveDocument.SaveAs Filename:="NewDoc.doc"
Wend
End With
End With
End Sub
Sub New_Doc()
Dim sWord As String
sWord = InputBox("Enter term to find", "Print pages")
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
While .Execute(findText:=sWord)
Selection.Extend
Application.Browser.Next
' copies selected page
Selection.Copy
' creates a new document and saves it
Documents.Add DocumentType:=wdNewBlankDocument
Selection.PasteAndFormat (wdPasteDefault)
ActiveDocument.SaveAs Filename:="NewDoc.doc"
Wend
End With
End With
End Sub