Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2004

Tip: Looking for answers? Try searching our database.

Strange results with Style/Font change macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Colleen - 16 Dec 2004 14:08 GMT
I have written the following macro for our firm:

   With ActiveDocument.Styles("Normal").Font
       .Name = "Times New Roman"
       .Size = 12
   End With

   Selection.WholeStory
   Selection.Style = ActiveDocument.Styles("Normal")
   Application.GoBack

Our firm default was CG Times until about a year ago.  However, often there
are documents that are re-used (don't get me started) and they are still in
the old CGT font.  Problem is, sometimes the font was applied via the Normal
style, and sometimes it was directly formatted.  At any rate, this macro
tries to cover all the bases.  I also wanted to be able to reapply the
Normal style without overriding any direct font attributes (i.e., bold,
underline, etc.).  This works perfectly except in this unusual situation.
If the first paragraph with text is formatted with one of those attributes
(i.e., bold), then any bold formatting is removed throughout the document.
Any other attributes, such as italics, are left alone.  All direct
formatting is left alone as long as the first paragraph with text in it does
not have any direct font formatting.  It's really strange.  Even if I put
blank paragraphs above the first one, it still looks at the first paragraph
with text in it as the deciding factor.

Anyone have any ideas on this?

Colleen
Klaus Linke - 16 Dec 2004 17:01 GMT
Hi Colleen,

It's even a bit weirder:
If more than 50% of the characters in the first paragraph are bold, bold is
removed in all the selection.
Else, bold is kept.

I don't like it either. But Word has quite a few such features where it
tries to guess what the user wants, and uses rules that are hard to fathom.

You could replace CG Times with TNR (using Edit > Replace).

Maybe it would be easier to simply remove the CG Times font file from your
machine(s), and set TNR as the default replacement for it in "Tools >
Options > Compatibility > Font substitution". It's enough to do that once.
And all old documents will then use TNR without your needing to change a
thing.
The documents will still use CG Times if you send them to someone who has CG
Times installed though.

Regards,
Klaus

> I have written the following macro for our firm:
>
[quoted text clipped - 25 lines]
>
> Colleen
Colleen - 16 Dec 2004 17:21 GMT
Very good insights, Klaus.  I especially like the option of removing the
font, but we do email our docs to clients a lot and I know the attorneys
wouldn't want any font surprises.

I think the best option is the Edit > Replace option you mentioned.  Don't
know why I didn't think of that before, but it works perfectly.  I'll just
edit the macro to modify the style, then do the Replace command for any text
that might have been directly formatted.

Thanks so much for your help!

Colleen

> Hi Colleen,
>
[quoted text clipped - 53 lines]
> >
> > Colleen
OughtFour - 17 Dec 2004 21:14 GMT
> Hi Colleen,
>
> It's even a bit weirder:
> If more than 50% of the characters in the first paragraph are bold, bold is
> removed in all the selection.
> Else, bold is kept.

In that case, why not

-insert new paragraph at the start of the document (Normal style), with VBA
-make sure it is not bold, with VBA
-run your code
-delete the paragraph, with VBA

Sometimes a workaround is good enough.
Chuck - 16 Dec 2004 19:53 GMT
Hi Colleen

If you apply Normal style to the entire document, then every paragraph will
be in Normal style, which may not be what you want.

If you want to be more selective you can cycle through all the paragraphs in
the range, test to see what style the paragraph is, then reapply the style to
that paragraph to change the font name without affecting attributes like
bold, italic, etc.

Note that you need to cycle through all the "story ranges" as well to make
sure you hit all headers, footers, footnotes, endnotes, etc.

Here's some sample code to get you started thinking about ways you can use
active document ranges and story ranges...  The sample uses "Arial" and
"Batang" font names but obviously will work with any font names, sizes etc
you choose.

sub ChangeStyles()

   Dim aPara As Paragraph
   Dim aStyle As Style
   Dim aStoryRange As Range
   Dim sParaStyleName As String
   
   On Error Resume Next
   
   With ActiveDocument
   
       With .Styles("Normal").Font
           .Name = "Arial"
           .Size = 12
       End With
       
       For Each aStoryRange In .StoryRanges
   
           For Each aPara In .Paragraphs
           
               For Each aStyle In .Styles
                       aPara.Style.Name = aPara.Style.Name
                       'this reapplies all styles so font
                       'changes if style is based on Normal
               Next aStyle
               
           Next aPara
           
           With aStoryRange.Find
               With .Replacement
                   With .Font
                       .Name = "Batang"
                   End With
                   .Font.Name = "Arial"
               End With
               .Text = "*"
               .Forward = True
               .Wrap = wdFindContinue
               .MatchWildcards = True
               .Execute Replace:=wdReplaceAll
           End With
   
       Next aStoryRange
   
   End With
   
end sub

> I have written the following macro for our firm:
>
[quoted text clipped - 25 lines]
>
> Colleen
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.