Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-28-2014, 02:30 PM
newbieX newbieX is offline Select section of text and change text Windows 7 64bit Select section of text and change text Office 2007
Novice
Select section of text and change text
 
Join Date: Mar 2014
Posts: 6
newbieX is on a distinguished road
Default Select section of text and change text

I have a word document that I want to select the entire text and reformat to Arial 10 except for a small section that will be Arial 8. I know the code for selecting all, but cannot seem to be able to just select the following text:

This chart is for reference only


Please do not distribute results
Date created 1/1/2013

Code I have for selecting all text is as follows:

Code:
Sub SelectAllText()

    Selection.WholeStory
    Selection.Font.Name = "Arial"
    Selection.Font.Size = 10
    Selection.Font.Color = wdColorAutomatic
    Selection.Collapse
    Selection.Find.Text = "This as a test"
    

End Sub
Suggestions as to how to select just the three sentences?

Many thanks in advance.
Reply With Quote
  #2  
Old 03-28-2014, 03:00 PM
fumei fumei is offline Select section of text and change text Windows 7 64bit Select section of text and change text Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

1. you should use Styles, rather than manual formatting
2. are the sentences contiguous?
Reply With Quote
  #3  
Old 03-28-2014, 03:46 PM
newbieX newbieX is offline Select section of text and change text Windows 7 64bit Select section of text and change text Office 2007
Novice
Select section of text and change text
 
Join Date: Mar 2014
Posts: 6
newbieX is on a distinguished road
Default

Quote:
Originally Posted by fumei View Post
1. you should use Styles, rather than manual formatting
2. are the sentences contiguous?
I think I figured it out. I just make the text a different color and change it that way. (I'm working from a template.)

It does what I want, so all is good. Suggestions on how to condense code would be nice. I'm always game to learn.

Code:
Sub ChangeColorWithReplace()

    Selection.WholeStory
    Selection.Font.Name = "Arial"
    Selection.Font.Size = 10
    Selection.Collapse
    Selection.Find.ClearFormatting
    Selection.Find.Font.Color = wdColorYellow
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Font.Color = wdColorAuto
    Selection.Find.Replacement.Font.Size = 8
    
    With Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchKashida = False
        .MatchDiacritics = False
        .MatchAlefHamza = False
        .MatchControl = False
        .MatchByte = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    
    Selection.Find.Execute Replace:=wdReplaceAll
    
    Selection.WholeStory
    Selection.Font.Color = wdColorAutomatic
    Selection.Collapse
End Sub
Reply With Quote
  #4  
Old 03-28-2014, 04:21 PM
fumei fumei is offline Select section of text and change text Windows 7 64bit Select section of text and change text Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

You asked about something to find a specific string of text. What you posted does not do this. It simply changes the document to Arial 10. If you used Styles (which is how Word is supposed to be used!!), you could do it with:
Code:
Sub MakeArial()
With Selection
   .WholeStory
   .Style = "MyArial"
End With
End Sub
Reply With Quote
Reply

Tags
selecting text, vba in microsoft word, word 2007

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Select section of text and change text How to find and select text in a document? mkhuebner Word VBA 8 02-04-2014 08:04 PM
Select section of text and change text Formatting- Apply changes to highlighted text results in same change to other text sential Word 6 01-10-2014 03:22 PM
Select section of text and change text How to select all text in a presentation (even if not in outline) smodtactical PowerPoint 1 05-10-2010 10:11 AM
Select section of text and change text Select text by color Invain Word 1 02-14-2010 07:08 AM
Select text between characters davers Word 10 05-24-2009 05:15 AM

Other Forums: Access Forums - Senior Forums

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