I am trying to loop through all the sentences in a Word document and parse them into semi-HTML code. During testing, I ran into an interesting situation where any sentence followed by a non-closed sentence would be skipped. For example, if I have the following two sentences:
This is the first sentence in a paragraph with special characters and there should be one more sentence. This is the second sentence that should be there.**
When I loop through each sentence in the paragraph.range.sentences, I only get the first sentence and the ".**" at the end of the paragraph. However, if I add a space between the period and the astriks, then the code works ". **".
How can I make sure the macro reads all the text in a sentence, even if there isn't a space after the period? My example code is below:
Public Sub ParseDoc()
Dim paras As Paragraphs
Dim para As Paragraph
Dim sents As Sentences
Dim sent As Range
Set paras = ActiveDocument.Paragraphs
For Each para In paras
Set sents = para.Range.Sentences
For Each sent In sents
MsgBox (sent.Text)
Next
Next
End Sub