Is it possible to extract specific sentences with same certain format and save them to a text file in Microsoft Word?
You can use VBA to automate the process.
- Open the document.
- Press Alt+F11 to open the VBA Editor.
- Copy and paste the code below.
- With your cursor inside the code, press F5 to run it. A new window will be opened with the extracted dialogues.
Sub GetDialogues()
Dim coll As New Collection
Dim regEx As RegExp
Dim allMatches As MatchCollection
Set regEx = New RegExp
With regEx
.IgnoreCase = False
.MultiLine = True
.Global = True 'Look for all matches
.Pattern = """.+?""" 'Pattern to look for
End With
Set allMatches = regEx.Execute(ActiveDocument.Content.Text)
For Each Item In allMatches
coll.Add Item 'Add found items to the collection
Next Item
Dim newdoc As Document
Set newdoc = Documents.Add 'Add a new Word document
newdoc.Activate 'Activate the document
For Each Item In coll
newdoc.Content.Text = newdoc.Content.Text + Item 'Add each item (quote) to the document
Next Item
newdoc.SaveAs FileName:="test.txt", Fileformat:=wdFormatPlainText 'Save the document as plain text
End Sub