Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-06-2016, 04:40 PM
Fred256 Fred256 is offline Setting part of a paragraph bold Windows 10 Setting part of a paragraph bold Office 2007
Novice
Setting part of a paragraph bold
 
Join Date: Oct 2016
Posts: 5
Fred256 is on a distinguished road
Default Setting part of a paragraph bold

Hi, I'm working thru a doc looking for matching paragraphs (one containing " - ").
If found I want split(ThisOne, " - ")(0) to be bold and split(ThisOne, " - ")(1) to be not bold.

Not sure how to tackle this.. There's not much to my code, pp is the string I start with is

For Each p In ActiveDocument.Paragraphs
pp = p.Range.Text



and I've found I can change pp then write it back with

p.Range.Text= pp

However, as it's only part of pp, I'm a bit stuck.

Thanks for any advice. I'm new to this.

Fred.
Reply With Quote
  #2  
Old 10-07-2016, 04:06 AM
gmayor's Avatar
gmayor gmayor is offline Setting part of a paragraph bold Windows 10 Setting part of a paragraph bold Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
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

Based on your other post in this forum
Code:
Dim p As Paragraph
Dim oRng As Range
Dim Thistext As String
Dim meetssomecondition As Boolean

    For Each p In ActiveDocument.Paragraphs
        meetssomecondition = False
        Thistext = p.Range.Text
        If InStr(1, Thistext, "-") > 0 Then meetssomecondition = True
        If meetssomecondition = True Then
            Set oRng = p.Range    'set a range to the paragraph
            oRng.Collapse 1    'collapse the range to its start
            oRng.MoveEndUntil "-"    'move the end of the range to the hyphen
            oRng.Font.Bold = True    'format the range
        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, 06:13 AM
Guessed's Avatar
Guessed Guessed is offline Setting part of a paragraph bold Windows 10 Setting part of a paragraph bold Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You could simplify the meetsomecondition setting or even avoid it completely with the following modifications
Code:
Sub BoldStart()
  Dim p As Paragraph, i As Integer
  Dim oRng As Range, meetssomecondition As Boolean

  For Each p In ActiveDocument.Paragraphs
    Set oRng = p.Range
    i = InStr(1, oRng.Text, "-")
    'meetssomecondition = i > 0
    'If meetssomecondition Then
      oRng.End = oRng.Start + i - 1
      oRng.Font.Bold = True
    'End If
  Next p
End Sub
The remmed out lines don't matter if there is no dash in the paragraph since the range is collapsed to an insertion point on those paragraphs.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #4  
Old 10-07-2016, 07:13 AM
gmayor's Avatar
gmayor gmayor is offline Setting part of a paragraph bold Windows 10 Setting part of a paragraph bold Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
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

Agreed the extra code is superfluous, but it relates to the OPs other thread so I left it in to avoid confusing the user even more.
__________________
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
  #5  
Old 10-07-2016, 02:54 PM
Fred256 Fred256 is offline Setting part of a paragraph bold Windows 10 Setting part of a paragraph bold Office 2007
Novice
Setting part of a paragraph bold
 
Join Date: Oct 2016
Posts: 5
Fred256 is on a distinguished road
Default

Thanks for the advice.. about to try out your suggestions
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting part of a paragraph bold Find, select, and replace part of text with bold paik1002 Word VBA 4 12-07-2015 11:24 PM
How to parse bold sections of a paragraph? XmisterIS Word VBA 2 03-31-2014 02:54 PM
Setting part of a paragraph bold Set style for part of paragraph meileetan Word 7 06-07-2013 01:09 AM
Setting part of a paragraph bold Set paragraph text to bold. Sorcerer13 Word 1 09-04-2012 11:08 AM
Setting part of a paragraph bold How to indent only half part of the paragraph 2em Samahu Word 2 01-17-2011 08:15 AM

Other Forums: Access Forums

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