Hello,
I am trying to determine by code if a phrase is on a line by itself. The phrase will be “QUESTION n”, where "n" is a number, and the phrase is on a line by itself. Sample text would look like:
QUESTION 1
What is the distance between the earth and the moon?
I can use “. MatchWildcards” to find the phrase, Question n, with no issues:
Code:
'total QUESTIONS
Dim wdApp As Object
Dim wdDoc As Object
Dim intQuesCount As Integer
Set wdApp = CreateObject("Word.Application")
wdApp.Visible = False
Set wdDoc = wdApp.Documents.Open(FileName:="C:\Users\roy\Desktop\sample.docx", AddToRecentFiles:=False, Visible:=False)
intQuesCount = 0
Set oRng = wdDoc.Range
With oRng.Find
.Text = "<QUESTION [0-9]{1,}"
.MatchWildcards = True
.MatchCase = True
While .Execute
intQuesCount = intQuesCount + 1 'count the number of occurrences
Wend
End With
MsgBox "There are " & intQuesCount & " occurrences."
It appear that using “^p” to find a paragraph mark is not compatible with “.MatchWildcards”. So, how do you determine if your found phrase is on a line by itself? Many thanks any advance for guidance!
Thanks,
Roy