Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-01-2023, 10:00 AM
RobiNew RobiNew is offline Find a word and then check if its paragraph is a list pargraph or not Windows 10 Find a word and then check if its paragraph is a list pargraph or not Office 2016
Competent Performer
Find a word and then check if its paragraph is a list pargraph or not
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default Find a word and then check if its paragraph is a list pargraph or not

I'm tryng to check if a paragraph containg the 'Found' word is a list paragraph or not. Can someone help with the tentative code here below? Thanks!


Code:
Sub ListOrNot()
Dim aRng As Range
Set aRng = ActiveDocument.Range
    With aRng.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Wrap = wdFindStop
      .Format = False
      .MatchCase = False
      .MatchWildcards = False
      .Text = "Title"
      .Execute
    End With
check = aRng.Find.Found.ListFormat.ListType
MsgBox check
End Sub
Reply With Quote
  #2  
Old 12-01-2023, 02:07 PM
vivka vivka is offline Find a word and then check if its paragraph is a list pargraph or not Windows 7 64bit Find a word and then check if its paragraph is a list pargraph or not Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Hi, RobiNew! This works for me:
Code:
Sub ListOrNot()
Dim aRng As range
Set aRng = ActiveDocument.range
    With aRng.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWildcards = False
        .text = "Title"
        If .Execute Then
            aRng.Select
            check = aRng.Paragraphs(1).range.ListFormat.ListType
            If check <> 0 Then
                MsgBox "This is a list paragraph"
            Else
                MsgBox "This is not a list paragraph"
            End If
        End If
     End With
  Set aRng = Nothing
End Sub
Reply With Quote
  #3  
Old 12-01-2023, 04:20 PM
gmaxey gmaxey is offline Find a word and then check if its paragraph is a list pargraph or not Windows 10 Find a word and then check if its paragraph is a list pargraph or not Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Vivka, RobiNew


Check is superfluous. If it wasn't, it isn't declared. If you declare variables, declare them all.


Code:
Sub ListOrNot()
Dim aRng As Range
Set aRng = ActiveDocument.Range
  With aRng.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWildcards = False
    .Text = "Title"
    If .Execute Then
      If aRng.Paragraphs(1).Range.ListFormat.ListType <> 0 Then
        MsgBox "This is a list paragraph"
      Else
        MsgBox "This is not a list paragraph"
      End If
    End If
   End With
  Set aRng = Nothing
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #4  
Old 12-02-2023, 12:49 AM
vivka vivka is offline Find a word and then check if its paragraph is a list pargraph or not Windows 7 64bit Find a word and then check if its paragraph is a list pargraph or not Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Yes, Greg, you are right! Thank you for your correction!
Reply With Quote
  #5  
Old 12-02-2023, 01:58 AM
RobiNew RobiNew is offline Find a word and then check if its paragraph is a list pargraph or not Windows 10 Find a word and then check if its paragraph is a list pargraph or not Office 2016
Competent Performer
Find a word and then check if its paragraph is a list pargraph or not
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default

Many thanks to you both! À la prochaine!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find longest paragraph in Word document keimba Word VBA 2 09-11-2019 03:26 PM
Find a word and then check if its paragraph is a list pargraph or not Find word, Insert Paragraph and bookmark gattaca714 Word VBA 2 03-24-2017 09:23 PM
Getting bold Pargraph kirkm Word VBA 11 09-19-2016 05:07 PM
Find Word then Highlight Whole Sentence and Paragraph Around it ChrisOK Word VBA 4 09-08-2016 10:16 PM
Find last word in paragraph and delete it Dave T Word VBA 3 05-21-2015 12:40 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:19 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