Reputation: 7
As a non-programmer, here are my beginning, non-VBA, thoughts on how to copy/paste the first sentence of every paragraph:
Dim Terminalpoint as String
Can I do this using VBA? How can I get started?
Upvotes: 0
Views: 6058
Reputation: 53623
Here is an example of extracting the first SENTENCE from each paragraph in a document. This would be code written in and called from Word Application.
Sub test()
Dim doc As Document
Dim p As Paragraph
Dim s As String
Set doc = ActiveDocument
For Each p In doc.Paragraphs
Debug.Print p.Range.Sentences(1)
Next
End Sub
From Excel, a simple routine to take each first sentence and place it in a new worksheet in the active Excel workbook:
Sub GetSentences()
'Word objects
Dim wdApp as Object
Dim doc as Object
Dim p as Object
Dim s as String
Dim ws as Worksheet
Set wdApp = CreateObject("Word.Application")
Set doc = wdApp.Documents.Open("c:\your filename.docx")
For each p in doc.Paragraphs
Set ws = Worksheets.Add
ws.Range("A1").Value = p.Range.Sentences(1)
Next
End Sub
Upvotes: 2