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

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?
 
S

Stefan Blom

You need to loop all paragraphs in the document, extract the first sentence,
copy it, and paste into a new target document.
 
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?

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!
 
S

Stefan Blom

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top