Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Wed, 18 Jun 2008 01:22:00 -0700,    group: microsoft.public.word.vba.customization        back       


Problem using paragraph and character styles in macro   
I have a macro that called a certain paragraph style and then applied 
overrides to that style in subsequent steps of macro. I created character 
styles to represent the overrides. Here is the before and after of the 
relevant piece of code:

 

BEFORE:

Selection.HomeKey Unit:=wdLine
    Selection.Style = ActiveDocument.Styles("Caution+Warning")
        With Selection.Font
            .Bold = True
            .Size = 16
            .ColorIndex = wdRed
        End With
    Selection.TypeText Text:="!"
        With Selection.Font
            .Bold = True
            .Size = 11
            .ColorIndex = wdRed
        End With
    Selection.TypeText Text:=vbTab & "WARNING:"

'Format text of warning
        With Selection.Font
            .Bold = False
            .Size = 11
            .ColorIndex = wdAuto
        End With
    Selection.TypeText Text:="  "

 

AFTER:

Selection.HomeKey Unit:=wdLine
    Selection.Style = ActiveDocument.Styles("Caution+Warning")
    Selection.Style = ActiveDocument.Styles("CR Font 16 Red")
    Selection.TypeText Text:="!"

    Selection.Style = ActiveDocument.Styles("CR Red Bold")
    Selection.TypeText Text:=vbTab & "WARNING:"

    Selection.Style = ActiveDocument.Styles("Caution+Warning")
    Selection.TypeText Text:="  "

 

Essentially, my intent is to have a warning style for a note where the 
lead-in to the note has character formatting applied but the text of the 
warning actually reverts to the base "Warning" paragraph style. This does not 
work. The text remains red and bold. I can't even toggle the bold off .

 

Does anyone have any ideas on this or can anyone refer me to another source 
for information? I can only guess that Word may require that I select the 
character that I want to apply the character style to rather than toggling it 
on when I want to use it. Toggling it on appears to work but apparently 
selecting another style does not remove the character format.




--------------------------------------------------------------------------------
David
date: Wed, 18 Jun 2008 01:22:00 -0700   author:   david

Re: Problem using paragraph and character styles in macro   
To use VBA to clear all manually applied character formatting (including 
character styles) from a selection or range, use the Font.Reset method of 
the selection or range.

-- 
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

"david"  wrote in message 
news:4DD5B102-4174-4D77-BEA7-5627D37C5540@microsoft.com...
>I have a macro that called a certain paragraph style and then applied
> overrides to that style in subsequent steps of macro. I created character
> styles to represent the overrides. Here is the before and after of the
> relevant piece of code:
>
>
>
> BEFORE:
>
> Selection.HomeKey Unit:=wdLine
>    Selection.Style = ActiveDocument.Styles("Caution+Warning")
>        With Selection.Font
>            .Bold = True
>            .Size = 16
>            .ColorIndex = wdRed
>        End With
>    Selection.TypeText Text:="!"
>        With Selection.Font
>            .Bold = True
>            .Size = 11
>            .ColorIndex = wdRed
>        End With
>    Selection.TypeText Text:=vbTab & "WARNING:"
>
> 'Format text of warning
>        With Selection.Font
>            .Bold = False
>            .Size = 11
>            .ColorIndex = wdAuto
>        End With
>    Selection.TypeText Text:="  "
>
>
>
> AFTER:
>
> Selection.HomeKey Unit:=wdLine
>    Selection.Style = ActiveDocument.Styles("Caution+Warning")
>    Selection.Style = ActiveDocument.Styles("CR Font 16 Red")
>    Selection.TypeText Text:="!"
>
>    Selection.Style = ActiveDocument.Styles("CR Red Bold")
>    Selection.TypeText Text:=vbTab & "WARNING:"
>
>    Selection.Style = ActiveDocument.Styles("Caution+Warning")
>    Selection.TypeText Text:="  "
>
>
>
> Essentially, my intent is to have a warning style for a note where the
> lead-in to the note has character formatting applied but the text of the
> warning actually reverts to the base "Warning" paragraph style. This does 
> not
> work. The text remains red and bold. I can't even toggle the bold off .
>
>
>
> Does anyone have any ideas on this or can anyone refer me to another 
> source
> for information? I can only guess that Word may require that I select the
> character that I want to apply the character style to rather than toggling 
> it
> on when I want to use it. Toggling it on appears to work but apparently
> selecting another style does not remove the character format.
>
>
>
>
> --------------------------------------------------------------------------------
> David
>
>
date: Wed, 18 Jun 2008 18:17:29 +0100   author:   Jonathan West

Re: Problem using paragraph and character styles in macro   
Jonathan:  is there a way to find paragraphs that have manual formatting 
applied?  I don't want to change them, just to find them.  

Could I apply the font.reset method and compare the paragraph after with the 
(cached) paragraph before?  Or is there something easier?

-  Jessica
date: Fri, 18 Jul 2008 14:15:03 -0700   author:   Jessica Weissman

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us