Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-16-2015, 09:39 AM
ksigcajun ksigcajun is offline Select text to be underline and bold Windows 7 64bit Select text to be underline and bold Office 2010 64bit
Advanced Beginner
Select text to be underline and bold
 
Join Date: May 2014
Posts: 76
ksigcajun is on a distinguished road
Default Select text to be underline and bold

I've created this macro to underline and bold specific text and number when found in my document.

Is there a way to combine and have the macro underline and bold in only one WITH statement? I may have complicated the macro, but it does work.

Thanks!

PHP Code:
Sub FormatMacro()
Dim oRng As Word.Range
Set oRng 
ActiveDocument.Range
           With oRng
.Find
    
.ClearFormatting
    
.Replacement.ClearFormatting
    
.Text "<Life Insurance>"


    
.Replacement.Text "^&"
    
.MatchWildcards True
    
.Format True
    
.Replacement.Font.Underline wdUnderlineSingle
    
.Execute Replace:=wdReplaceAll
         End With
        Set oRng 
ActiveDocument.Range
  With oRng
.Find
    
.ClearFormatting
    
.Replacement.ClearFormatting
    
.Text "<2.4.9>"
    
.Replacement.Text "^&"
    
.MatchWildcards True
    
.Format True
    
.Replacement.Font.Bold wdBoldSingle
    
.Execute Replace:=wdReplaceAll
  End With
  End Sub 
Reply With Quote
  #2  
Old 03-16-2015, 07:51 PM
Guessed's Avatar
Guessed Guessed is offline Select text to be underline and bold Windows 7 32bit Select text to be underline and bold Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 1,936
Guessed is a name known to allGuessed is a name known to allGuessed is a name known to allGuessed is a name known to allGuessed is a name known to allGuessed is a name known to all
Default

I'm surprised that it does work because I didn't know that there was a Word constant for wdBoldSingle - you should be using a boolean there.

You can simplify the code to
Code:
Sub FormatMacro()
  Dim oRng As Word.Range
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "<Life Insurance>"
    .Replacement.Text = ""
    .MatchWildcards = True
    .Format = True
    .Replacement.Font.Underline = wdUnderlineSingle
    .Execute Replace:=wdReplaceAll

    .Replacement.ClearFormatting
    .Text = "<2.4.9>"
    .Replacement.Font.Bold = True
    .Execute Replace:=wdReplaceAll
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Microsoft Word macro to find text, select all text between brackets, and delete helal1990 Word VBA 4 02-05-2015 03:52 PM
Select text to be underline and bold Not Bold text but it comes up bold Pluviophile Word 7 10-22-2013 10:29 AM
Format Bold in one line makes all lines bold Nitte Word 2 02-07-2013 12:34 AM
Select text to be underline and bold Set paragraph text to bold. Sorcerer13 Word 1 09-04-2012 11:08 AM
How to remove the UNDERLINE from a hyperlink text? Learner7 PowerPoint 3 05-17-2010 09:35 PM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 01:05 AM.


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