#1
|
|||
|
|||
Find out how to change all letter of first word using VBA ?
Hi,
Sorry Sorry sorry for my english For my dissertation today at more than 400 pages, I would like to change the style and box of certain words. I found my happiness ... well almost. In the example below, I need to modify "DESCRIPTION" in one style and "-- remplissage" in another style This is my macro : Code:
Sub change () Application.ScreenUpdating = False Selection.HomeKey Unit:=wdStory Do With Selection.Find .ClearFormatting .Text = "COORDINATION" .MatchWholeWord = True .Font.Bold = False .Font.Underline = True .Style = "Souligné" .MatchCase = True .Wrap = wdFindStop .Execute End With If Selection.Find.Found Then Selection.Style = ActiveDocument.Styles("NORMAL_01") Selection.Range.Case = wdUpperCase End If Loop Until Not Selection.Find.Found End Sub EX : DESCRIPTION (yes) This is a description (NO) de my car ... Thanks in advance and sorry for my english |
#2
|
||||
|
||||
The following will change the style of the word 'description' if in upper case or starting a sentence.
Note that the macro calls a character style - here the built-in style 'Strong'. If you call a paragraph style the chances are that the whole paragraph containing the word will be so formatted, so I suggest creating a character style to achieve the formatting you require. Code:
Sub Macro1() Dim oRng As Range Dim vFind As Variant Dim i As Integer vFind = Array("DESCRIPTION", "Description") For i = 0 To UBound(vFind) Set oRng = ActiveDocument.Range With oRng.Find .ClearFormatting .Text = vFind(i) Do While .Execute(findText:=vFind(i), MatchWholeWord:=True, MatchCase:=True) oRng.Style = "Strong" 'Change as appropriate Loop End With Next i Set oRng = Nothing End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
Tags |
allcaps matchcase |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Is there a way to only find the first letter of each line? (Word 97) | Genericname1111 | Word | 4 | 09-11-2019 06:26 PM |
Find a letter or symbol with a specific font | Lou_Reed | Word | 1 | 11-15-2018 09:14 AM |
Change Letter Format in Word | GR_mahdi | Word VBA | 1 | 06-12-2017 08:24 PM |
Find and replace with a macro, problem with letter case | garcanrya | Word VBA | 2 | 01-10-2014 05:40 AM |
if letter change font also change | gsrikanth | Excel | 1 | 05-15-2012 03:03 AM |