![]() |
|
#1
|
|||
|
|||
|
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."
Thanks, Roy |
|
#2
|
||||
|
||||
|
Use ^13 instead of ^p with wildcards - Replace using wildcards
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#3
|
|||
|
|||
|
Ah, so simple! Thanks, Graham!
|
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
how to determine the exact middle point of a line in a shape?
|
blackroz | PowerPoint | 8 | 11-05-2015 10:38 AM |
Underlining a Phrase causes the whole document to be underlined
|
goldye | Word | 1 | 01-28-2015 02:08 PM |
| Insert <tab> in a phrase with condition | kjxavier | Word | 1 | 08-01-2014 08:57 PM |
Exclude phrase from email
|
kiwiora | Outlook | 2 | 07-16-2012 03:03 PM |
How to find exact phrase
|
CabbageTree | Outlook | 2 | 05-14-2012 11:24 AM |