#1
|
|||
|
|||
Changing color font between 2 specific flags
Hi everyone,
Just as a brief introduction, I'm comfortable using VBA on Excel and doing all sorts of interesting stuff, but I never used VBA on Word. I am currently struggling with the following situation: what I'd like to, is to build a macro that will change color (and size) for the text between 2 specific flags. For example, if my text is: Et quoniam mirari posse quosdam peregrinos existimo haec lecturos forsitan, si contigerit, quamobrem cum oratio ad ea monstranda deflexerit quae Romae gererentur. /Ex: nihil praeter seditiones narratur et tabernas et vilitates harum similis alias, summatim causas perstringam nusquam a veritate sponte propria digressurus./Ex I want Word to see the flag "/Ex:" and to apply a specific change in color and size to all the text between "/Ex:" and the second flag "/Ex". (And that for the whole document of course.) I've no idea where to start with. I browsed the net but only found topics that use a find/replace function which is not applicable in my case I think. I also thought about a macro built like a loop, selecting each word and checking if it's a flag or not, but first, I don't really know how to compute it, and second I don't think this is a very optimized solution. I will appreciate any kind of help! Thanks |
#2
|
||||
|
||||
You don't actually need a macro for what you've described; it could also be done with a wildcard Find/Replace, where:
Find = /Ex:*/Ex Replace = "^&" and you specify the replacement font colour. A macro equivalent is: Code:
Sub Demo() Application.ScreenUpdating = False With ActiveDocument.Range.Find .ClearFormatting .Replacement.ClearFormatting .Replacement.Font.ColorIndex = wdRed .Text = "/Ex:*/Ex" .Replacement.Text = "^&" .Format = True .Forward = True .Wrap = wdFindContinue .MatchWildcards = True .Execute Replace:=wdReplaceAll End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Thanks for the answer macropod, I didn't know that function.
Your macro works fine, but surprisingly when I try doing it manually, it doesn't find anything. Do you think it is linked to the language of my Office? BTW what does ^& stand for? Thanks in advance, |
#4
|
||||
|
||||
Quote:
Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Ok my mistake, I didn't know what you were referring to by "wildcards". It's very clear now and works!
Thank you very much for your help macropod! |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
changing the font color | dbsoccer | Project | 1 | 11-01-2013 06:21 AM |
changing color | aerospace | Outlook | 0 | 04-03-2013 05:56 AM |
Changing bar color automatically | Mahmuz | PowerPoint | 0 | 03-28-2012 11:49 PM |
Changing the margins on a specific paragraph | Xmosis | Word | 1 | 03-15-2011 02:04 PM |
changing font size without changing leading | carolns | Word | 1 | 09-14-2009 12:30 PM |