Automating a style change within a document

M

MichaelB

Hello,

Can someone help me automate the below Marco? I have a 535 page document
with over 1,100 “Justification:†paragraph entries within and I need to
reformat them all. Note: this document spans multiple WORD versions and
authors therefore these “Justification:†paragraph entries have several
styles associated throughout the document. This therefore eliminates the
option of just modifying the existing styles. It is my hope to reformat these
entries to the Paragraph 1 style throughout the document via a macro to save
my sanity.

Here is an example of one of my “Justification:†entries;

Justification: Users need the ability to view all pertinent data for the
subscriptions listed in this report.

Is it possible to get the macro to find all occurrences of the
“Justification:â€, select the entire paragraph, clear the formatting,
implement the Paragraph 1 style, as well as BOLD the text up to the colon
:))?

Any help would be greatly appreciated.
Mike



Sub fix_Paragraph1_Font_Bold()
'
Selection.ClearFormatting
Selection.ClearFormatting
Selection.Style = ActiveDocument.Styles("Paragraph 1")
Selection.HomeKey Unit:=wdLine
Selection.Find.ClearFormatting
With Selection.Find
.Text = "*:"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.Font.Bold = wdToggle
Selection.HomeKey Unit:=wdLine
End Sub
 
J

Jay Freedman

Hi Michael,

Here you go... First make sure the Paragraph 1 style is defined in the
document.

Sub ReformatJustifications()
Dim oRg As Range
Set oRg = ActiveDocument.Range
With oRg.Find
.Text = "Justification:"
.MatchCase = True
.Format = False
.Forward = True
.Wrap = wdFindStop
Do While .Execute
oRg.Style = ActiveDocument.Styles("Paragraph 1")
oRg.Paragraphs(1).Range.Font.Reset
oRg.Bold = True
oRg.Collapse wdCollapseEnd
Loop
End With
End Sub

If there is direct font formatting (bold, italic, etc.) that should be
retained, comment out the .Reset line.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
M

MichaelB

Jay,

This works perfectly, I just wish I understood how it is doing it. I thank
you for saving me the mundane task of having to select all these occurrences
throughout the document. You truly are a life save,, thanks much..

Is there anyway I can get you take a look at another post I have (subject:
Altering a style without modifying a table’s style?)? I need to get this one
sorted out so I can carry on with the document clean up.

Any help in getting this one answered would be extremely appreciated.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top