Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-29-2021, 04:08 PM
jeffreybrown jeffreybrown is offline Separate text by numbers and change font Windows 10 Separate text by numbers and change font Office 2016
Expert
Separate text by numbers and change font
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default Separate text by numbers and change font

Hi All,



The first part of this I have fine with using the below. The part that isn't working is the changing of the font and color. I used the macro recorder, but apparently the syntax doesn't fit right.

Code:
Sub CleanUpLines2()
    Application.ScreenUpdating = False
    With ActiveDocument.Range.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        With .Replacement.Font
            .Bold = True
            .Color = -721371137
        End With
        .Wrap = wdFindContinue
        .Format = False
        .MatchWildcards = True
        .Text = "([0-9]{1,2} )"
        .Replacement.Text = "^p\1"
        .Execute Replace:=wdReplaceAll
    End With
    Application.ScreenUpdating = True
End Sub
Here is what I got from the recorded macro.

Code:
Sub Macro6()
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find.Replacement.Font
        .Bold = True
        .Color = -721371137
    End With
    With Selection.Find
        .Text = "([0-9]{1,2} )"
        .Replacement.Text = "^p\1"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Reply With Quote
  #2  
Old 09-29-2021, 08:10 PM
Guessed's Avatar
Guessed Guessed is offline Separate text by numbers and change font Windows 10 Separate text by numbers and change font Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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

Is there a reason your crafted code says ".Format = False" when the recorded code sets this to True?

Note that this would likely result in the paragraph mark being coloured & bold which would apply that to automatic paragraph numbers as a result - this might not be your intention.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 09-30-2021, 05:02 AM
jeffreybrown jeffreybrown is offline Separate text by numbers and change font Windows 10 Separate text by numbers and change font Office 2016
Expert
Separate text by numbers and change font
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

Thanks Andrew. That was indeed the answer. I was using a boiler plate code and just didn't read all of the variable close enough.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Separate text by numbers and change font change font for all page numbers lemonphenomenon Word 17 12-19-2020 03:20 PM
Separate text by numbers and change font How to change the font color of specific text within a Word table cell epid011 Word Tables 2 05-15-2017 05:21 PM
how to search and replace BOLD text >> font color change? dylansmith Word 4 03-12-2013 09:51 PM
Separate heading numbers darksupernova Word 16 03-02-2013 06:09 AM
How to change line height for marked text (in Word 2007)? ... as default for font? pstein Word 1 01-14-2012 10:15 AM

Other Forums: Access Forums

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