Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-27-2022, 01:38 AM
Bikram Bikram is offline Detecting_paragraph Windows 10 Detecting_paragraph Office 2007
Advanced Beginner
Detecting_paragraph
 
Join Date: Jul 2021
Location: Nepal
Posts: 90
Bikram is on a distinguished road
Default Detecting_paragraph

Greeting,


I am wondering if paragraphs containing more than 1 line can be detected in word by using something like
Code:
    If Selection.paragraphs(1).range.count <> then
    'If true then formats in one way else formats in another way.
    End If
But unfortunately, line.count method does not seem to exist. How can it be detected? I really appreciate any help you can provide.
Reply With Quote
  #2  
Old 11-27-2022, 05:10 AM
gmayor's Avatar
gmayor gmayor is offline Detecting_paragraph Windows 10 Detecting_paragraph Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You could use the following function to count the number of lines in a range
Code:
Function NumLines(Rng As Range) As LongPtr
'Graham Mayor - http://www.gmayor.com
Const wdStatisticLines As LongPtr = 1
    NumLines = Rng.ComputeStatistics(wdStatisticLines)
lbl_Exit:
    Exit Function
End Function
Call it from your process e.g.
Code:
Sub macro1()
MsgBox NumLines(Selection.Paragraphs(1).Range)
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 11-27-2022, 10:28 PM
Bikram Bikram is offline Detecting_paragraph Windows 10 Detecting_paragraph Office 2007
Advanced Beginner
Detecting_paragraph
 
Join Date: Jul 2021
Location: Nepal
Posts: 90
Bikram is on a distinguished road
Default

Thanks gmayor, It works like charm.
Reply With Quote
  #4  
Old 11-28-2022, 12:13 AM
macropod's Avatar
macropod macropod is offline Detecting_paragraph Windows 10 Detecting_paragraph Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Do be aware that approach returns 0 regardless of the line count when the paragraph is in a table cell.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Other Forums: Access Forums

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


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