Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-06-2020, 03:16 AM
scienceguy scienceguy is offline Determine if a Phrase is on a Line by Itself Windows 10 Determine if a Phrase is on a Line by Itself Office 2016
Advanced Beginner
Determine if a Phrase is on a Line by Itself
 
Join Date: Feb 2019
Posts: 46
scienceguy is on a distinguished road
Default Determine if a Phrase is on a Line by Itself

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
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Determine if a Phrase is on a Line by Itself how to determine the exact middle point of a line in a shape? blackroz PowerPoint 8 11-05-2015 10:38 AM
Determine if a Phrase is on a Line by Itself 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
Determine if a Phrase is on a Line by Itself Exclude phrase from email kiwiora Outlook 2 07-16-2012 03:03 PM
Determine if a Phrase is on a Line by Itself How to find exact phrase CabbageTree Outlook 2 05-14-2012 11:24 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:05 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft