Select, copy and past first sentence from each paragraph to adifferent document

  • Thread starter Thread starter actnt8528
  • Start date Start date
A

actnt8528

I've spent way too many hours trying trying to figure out a method to pull first sentences from an open document.

Is there a macro out there that will select the first sentence from every paragraph in the document, and then copy/paste it into a new document?
 
You need to loop all paragraphs in the document, extract the first sentence,
copy it, and paste into a new target document.
 
I've spent way too many hours trying trying to figure out a method to pull first sentences from an open document.



Is there a macro out there that will select the first sentence from every paragraph in the document, and then copy/paste it into a new document?

Stefan,

Yes, that is the correct workflow...is there a macro available that will do that? Or can you point me to where I can find the VBA code that would work for this?

Thanks!
 
The following code inserts the first sentence of each paragraph in the
active document into a new, blank document. (Each sentence is placed in a
separate paragraph in the target document.)

Sub testmacro()
Dim i As Long
Dim numpara As Long
Dim newdoc As Document
Dim currentdoc As Document
Dim r As Range

Set currentdoc = ActiveDocument
Set newdoc = Documents.Add
Set r = newdoc.Content.Duplicate
numpara = currentdoc.Paragraphs.Count

For i = 1 To numpara
currentdoc.Paragraphs(i).Range.Sentences(1).Copy
r.Collapse wdCollapseEnd
r.Paste
r.InsertParagraphAfter
Next i
End Sub

The macro uses copy and paste and it can probably be improved, but it seems
to do the job.
 
Back
Top