How to export the results of a word search using word 2013?

How can I copy or export the results of a word search into a word file or excel.   At minimum I just need to perform a copy and paste of my search results into a word document.  More would be better but for now this would help.
Answer
Answer

Here's one way:

  1. Press Ctrl+H to open the Replace dialog.
  2. Select the Find tab.
  3. Type your search string into the "Find what" box.
  4. Click Find In and select Main Document.
  5. This will select all results.
  6. Click the title bar of the document to return focus to the document without deselecting the results.
  7. Press Ctrl+C to copy the selected text.
  8. You can then paste the results into another Word document (each result will be a separate paragraph) or an Excel sheet (each result will be a separate cell).
Microsoft MVP (Word) since 1999
Fairhope, Alabama USA
http://ssbarnhill.com
http://wordfaqs.ssbarnhill.com
Screen shots captured with TechSmith's Snagit

24 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Answer
Answer

It's not at all clear what you want to copy, aside from whatever your search term is. For a possible solution, that outputs the sentence the found text occurs in, try:

Sub Demo()
Application.ScreenUpdating = False
Dim StrFnd As String, StrOut As String, Rng As Range
StrFnd = InputBox(Prompt:="String to Find")
If Trim(StrFnd) = "" Then Exit Sub
StrOut = "Sentences containing '" & StrFnd & "'" & vbTab & "page"
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = True
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Text = StrFnd
    .Replacement.Text = ""
    .Execute
  End With
  Do While .Find.Found
    StrOut = StrOut & vbCr & .Sentences.Last.Text & vbTab & _
      .Information(wdActiveEndAdjustedPageNumber)
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
StrOut = Replace(Replace(StrOut, Chr(12), ""), vbCr & vbTab, vbTab)
Set Rng = ActiveDocument.Range
With Rng
  .Collapse wdCollapseEnd
  .Text = StrOut
  .ConvertToTable vbTab
  With .Tables(1)
    With .Rows(1)
      .HeadingFormat = True
      .Range.Font.Bold = True
    End With
  End With
End With
Application.ScreenUpdating = True
End Sub

Do be aware, though, that VBA has no idea what a grammatical sentence is. For example, consider the following:

Mr. Smith spent $1,234.56 at Dr. John's Grocery Store, to buy: 10.25kg of potatoes; 10kg of avocados; and 15.1kg of Mrs. Green's Mt. Pleasant macadamia nuts.

For you and me, that would count as one sentence; for VBA it counts as 5...

Cheers
Paul Edstein
(Fmr MS MVP - Word)

8 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated April 17, 2024 Views 10,648 Applies to: