Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-06-2016, 08:06 PM
Fred256 Fred256 is offline For next fail Windows 10 For next fail Office 2007
Novice
For next fail
 
Join Date: Oct 2016
Posts: 5
Fred256 is on a distinguished road
Default For next fail


Kind of curious why this never moves to Next Paragraph ?
If line <<<<< is remmed out it does, but still has me baffled.

Code:
For Each p In ActiveDocument.Paragraphs
   Thistext = p.Range.Text
   Debug.Print Thistext
    If meetssomecondition = True Then
      p.Range.Font.Bold = True
      p.Range.Text = Thistext <<<<<
    End If
Next
Reply With Quote
  #2  
Old 10-07-2016, 03:59 AM
gmayor's Avatar
gmayor gmayor is offline For next fail Windows 10 For next fail Office 2016
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

Adding this line, simply removes the formatting you have added, by replacing the range with what it was originally. What you should have is

Code:
Dim p As Paragraph 'Declare your variables
Dim Thistext As String
Dim meetssomecondition As Boolean

    For Each p In ActiveDocument.Paragraphs
        meetssomecondition = False 'Set the boolean value to false for each paragraph0
        Thistext = p.Range.Text 'Record the text content of the paragraph range
Debug.Print Thistext 
        If Left(Thistext, 5) = "Lorem" Then meetssomecondition = True 'add a condition relating to the text that will set the boolean value to True
        If meetssomecondition = True Then 'If that condition is met set the paragraph range to bold font
            p.Range.Font.Bold = True
        End If
    Next p
__________________
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 10-07-2016, 02:52 PM
Fred256 Fred256 is offline For next fail Windows 10 For next fail Office 2007
Novice
For next fail
 
Join Date: Oct 2016
Posts: 5
Fred256 is on a distinguished road
Default

Thanks very much for the correction, which I'll have a play with.
I'm still not sure why the failure... even if the original range was restored the code instruction 'Next' would still be executed (you'd think).
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert File Printout w/ PDF fail jsilvoy OneNote 0 03-05-2015 06:44 PM
Fail to insert “table of content”, Jamal NUMAN Word 7 11-16-2013 01:21 AM
Big presentation, links fail: solution theredspecial PowerPoint 6 08-26-2013 10:35 PM
Office repair fail markg2 Office 1 08-18-2013 07:23 AM
Shortcuts Fail sussertown Outlook 0 02-16-2009 06:38 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:46 PM.


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