Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-12-2022, 12:11 AM
gmayor's Avatar
gmayor gmayor is offline VBA to select a specific font type Windows 10 VBA to select a specific font type Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
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 ofgmayor has much to be proud of
Default

You cannot select non-contiguous items with VBA. You can select them sequentially, but then there would have to be some point in doing so. What do you want to do with them once found?
E.g. The following will highlight the texts so formatted:
Code:
Sub Macro1()
    With Selection.Find
        .ClearFormatting
        With .Font
            .Name = "Times New Roman"
            .Size = 12
            .Bold = True
        End With
        .Replacement.ClearFormatting

        Options.DefaultHighlightColorIndex = wdYellow
        .Replacement.Highlight = True

        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute Replace:=wdReplaceAll
    End With
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
  #2  
Old 01-12-2022, 09:03 AM
burniksapwet burniksapwet is offline VBA to select a specific font type Windows 10 VBA to select a specific font type Office 2007
Novice
VBA to select a specific font type
 
Join Date: Jan 2022
Posts: 6
burniksapwet is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
You cannot select non-contiguous items with VBA. You can select them sequentially, but then there would have to be some point in doing so. What do you want to do with them once found?
E.g. The following will highlight the texts so formatted:
Code:
Sub Macro1()
    With Selection.Find
        .ClearFormatting
        With .Font
            .Name = "Times New Roman"
            .Size = 12
            .Bold = True
        End With
        .Replacement.ClearFormatting

        Options.DefaultHighlightColorIndex = wdYellow
        .Replacement.Highlight = True

        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute Replace:=wdReplaceAll
    End With
End Sub
This is absolutely amazing. And yes I wanted it highlighted, I forgot to mention that. Thank you so much for looking into this and creating it for me. Much appreciated.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to select a specific font type Merging two Word documents: 2nd document not maintaining original font type and font size Swarup Word 31 08-28-2018 06:55 PM
Macro that swaps out font type namedujour Word 3 08-01-2018 01:27 PM
Font Type changes with change in language animex Word 1 09-08-2017 05:23 PM
VBA to select a specific font type Type 1 font d4okeefe Word 3 02-09-2016 01:16 AM
Mysterious Font Type Symbol curiousUser Word 2 08-18-2014 05:10 AM

Other Forums: Access Forums

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


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