Styles defined in VBA lose their shortcuts (aliases) - but not always 
Author Message
 Styles defined in VBA lose their shortcuts (aliases) - but not always

Hello all.  First off I really need to express my gratitude to you all
for your help to the world.  I'd like to be able to contribute, and
once I have this little project working, it's getting out to the
world!

Background
----------
I am using Word 2002 and writing templates for Word 2000.  I don't
have Word 2000, so I'm being as careful as I can.  I've stated the
problem beneath all this background blather.

I'm creating styles which will eventually be tied to numbering.  I've
got my style creation routines more or less working (*huge* props to
Dave Rado, Margaret Aldis, John McGhie, and many others).  My client
wants aliases to the style names, not for convenience, but for
identification.  Here's a sample:

...preliminary stuff...
ActiveDocument.Styles.Add Name:="Heading 1,H1_A B C", _
   Type:=wdStyleTypeParagraph
With ActiveDocument.Styles("Heading 1,H1_A B C")
...style definition...

Extra Detail
------------
1. Yes, I know Heading 1 exists.  I've trapped the Add error and have
told my routine to ignore it.  There seems to be no problem with the
redefinition.

2. The style alias is in three parts as illustrated above.  A typical
alias say, for Heading 1, might be "PRJ_Heading Level 1" and in my
code it would show as ActiveDocument.Styles.Add Name:="Heading
1,PRJ_Heading Level 1",   Type:=wdStyleTypeParagraph.

3. Headings 1 through 5 are main headings.  6 is not used.  7 through
9 are Appendix headings.

4. Each Add statement is identical, but for the numeric portion.
(They better be - they were made by a combination of the macro
recorder and copy/paste.)

The Problem
-----------
After the routine runs, I look at the style names, and the aliases
have vanished from all but two of the headings!  Seriously!  What I
get is:

Heading 1
Heading 2,PRJ_Heading Level 2
Heading 3
Heading 4
Heading 5
Heading 6
Heading 7
Heading 8,PRJ_Heading Level 8
Heading 9

What I _should_ get is:

Heading 1,PRJ_Heading Level 1
Heading 2,PRJ_Heading Level 2
Heading 3,PRJ_Heading Level 3
Heading 4,PRJ_Heading Level 4
Heading 5,PRJ_Heading Level 5
Heading 6,PRJ_Heading Level 6
Heading 7,PRJ_Heading Level 7
Heading 8,PRJ_Heading Level 8
Heading 9,PRJ_Heading Level 9

The styles seem to function, and I do get the expected heading and
numbering behaviour.  But the appearance is not at all what they
require, and more importantly, I'm worried it might be indiciative of
something more serious.

Thanks in advance for your thoughts!

Neman Syed



Sun, 06 Feb 2005 14:01:39 GMT  
 Styles defined in VBA lose their shortcuts (aliases) - but not always
I am not using Word 2002, so I'm no expert there, but I would first check
Tools -> Templates and Add-ins.  Is the "Automatically Update Document
Styles" option turned on?  If it is, I would turn it off on general
principles -- and it might even be related to this problem.  Your clients
should turn it off, too.  You might want to set Document.UpdateStylesOnOpen
to False, just to ensure this.

BTW, why alias the built-in styles?  Why not just create new styles by
copying the built-in styles and renaming them?  It seems that this would
ensure that no other (ill-bred) code would be making assumptions about your
new styles, or writing over them, as may be happening with the built-in
styles.

Lisa

P.S.  Unrelated to your post, but to my comments: I think everyone should
also turn off "Define styles based on your formatting" under Tools ->
AutoCorrect on the Auto Format as You Type tab.


Quote:
> Hello all.  First off I really need to express my gratitude to you all
> for your help to the world.  I'd like to be able to contribute, and
> once I have this little project working, it's getting out to the
> world!

> Background
> ----------
> I am using Word 2002 and writing templates for Word 2000.  I don't
> have Word 2000, so I'm being as careful as I can.  I've stated the
> problem beneath all this background blather.

> I'm creating styles which will eventually be tied to numbering.  I've
> got my style creation routines more or less working (*huge* props to
> Dave Rado, Margaret Aldis, John McGhie, and many others).  My client
> wants aliases to the style names, not for convenience, but for
> identification.  Here's a sample:

> ...preliminary stuff...
> ActiveDocument.Styles.Add Name:="Heading 1,H1_A B C", _
>    Type:=wdStyleTypeParagraph
> With ActiveDocument.Styles("Heading 1,H1_A B C")
> ...style definition...

> Extra Detail
> ------------
> 1. Yes, I know Heading 1 exists.  I've trapped the Add error and have
> told my routine to ignore it.  There seems to be no problem with the
> redefinition.

> 2. The style alias is in three parts as illustrated above.  A typical
> alias say, for Heading 1, might be "PRJ_Heading Level 1" and in my
> code it would show as ActiveDocument.Styles.Add Name:="Heading
> 1,PRJ_Heading Level 1",   Type:=wdStyleTypeParagraph.

> 3. Headings 1 through 5 are main headings.  6 is not used.  7 through
> 9 are Appendix headings.

> 4. Each Add statement is identical, but for the numeric portion.
> (They better be - they were made by a combination of the macro
> recorder and copy/paste.)

> The Problem
> -----------
> After the routine runs, I look at the style names, and the aliases
> have vanished from all but two of the headings!  Seriously!  What I
> get is:

> Heading 1
> Heading 2,PRJ_Heading Level 2
> Heading 3
> Heading 4
> Heading 5
> Heading 6
> Heading 7
> Heading 8,PRJ_Heading Level 8
> Heading 9

> What I _should_ get is:

> Heading 1,PRJ_Heading Level 1
> Heading 2,PRJ_Heading Level 2
> Heading 3,PRJ_Heading Level 3
> Heading 4,PRJ_Heading Level 4
> Heading 5,PRJ_Heading Level 5
> Heading 6,PRJ_Heading Level 6
> Heading 7,PRJ_Heading Level 7
> Heading 8,PRJ_Heading Level 8
> Heading 9,PRJ_Heading Level 9

> The styles seem to function, and I do get the expected heading and
> numbering behaviour.  But the appearance is not at all what they
> require, and more importantly, I'm worried it might be indiciative of
> something more serious.

> Thanks in advance for your thoughts!

> Neman Syed



Tue, 08 Feb 2005 17:40:38 GMT  
 Styles defined in VBA lose their shortcuts (aliases) - but not always
Hi Lisa,

I don't know what Neman's exact use for these heading styles is, but it has
been my experience that user created styles will not behave the same as
heading styles when it comes to outline promote/demote (and it sounds like
he's using these for numbering so this could be an issue).

The Outline Promote/Demote works ONLY w/ "heading" styles.  No matter HOW
you format a user defined style (including an outline level and linking it
to a list template makes no difference...) the Word Outline promote/demote
feature won't work w/ it.

I encountered this because I wanted to create multiple outlines for a single
document -- and there's only ONE "Heading 1 -- 9.  Ultimately I had to write
code that trapped the outline promote/demote command and replaced it w/ my
own thing.  (I didn't write the code, some kind soul on this forum helped
me.)

It was MADNESS!!!! (But it works great now.)


Quote:
> I am not using Word 2002, so I'm no expert there, but I would first check
> Tools -> Templates and Add-ins.  Is the "Automatically Update Document
> Styles" option turned on?  If it is, I would turn it off on general
> principles -- and it might even be related to this problem.  Your clients
> should turn it off, too.  You might want to set

Document.UpdateStylesOnOpen
Quote:
> to False, just to ensure this.

> BTW, why alias the built-in styles?  Why not just create new styles by
> copying the built-in styles and renaming them?  It seems that this would
> ensure that no other (ill-bred) code would be making assumptions about
your
> new styles, or writing over them, as may be happening with the built-in
> styles.

> Lisa

> P.S.  Unrelated to your post, but to my comments: I think everyone should
> also turn off "Define styles based on your formatting" under Tools ->
> AutoCorrect on the Auto Format as You Type tab.



> > Hello all.  First off I really need to express my gratitude to you all
> > for your help to the world.  I'd like to be able to contribute, and
> > once I have this little project working, it's getting out to the
> > world!

> > Background
> > ----------
> > I am using Word 2002 and writing templates for Word 2000.  I don't
> > have Word 2000, so I'm being as careful as I can.  I've stated the
> > problem beneath all this background blather.

> > I'm creating styles which will eventually be tied to numbering.  I've
> > got my style creation routines more or less working (*huge* props to
> > Dave Rado, Margaret Aldis, John McGhie, and many others).  My client
> > wants aliases to the style names, not for convenience, but for
> > identification.  Here's a sample:

> > ...preliminary stuff...
> > ActiveDocument.Styles.Add Name:="Heading 1,H1_A B C", _
> >    Type:=wdStyleTypeParagraph
> > With ActiveDocument.Styles("Heading 1,H1_A B C")
> > ...style definition...

> > Extra Detail
> > ------------
> > 1. Yes, I know Heading 1 exists.  I've trapped the Add error and have
> > told my routine to ignore it.  There seems to be no problem with the
> > redefinition.

> > 2. The style alias is in three parts as illustrated above.  A typical
> > alias say, for Heading 1, might be "PRJ_Heading Level 1" and in my
> > code it would show as ActiveDocument.Styles.Add Name:="Heading
> > 1,PRJ_Heading Level 1",   Type:=wdStyleTypeParagraph.

> > 3. Headings 1 through 5 are main headings.  6 is not used.  7 through
> > 9 are Appendix headings.

> > 4. Each Add statement is identical, but for the numeric portion.
> > (They better be - they were made by a combination of the macro
> > recorder and copy/paste.)

> > The Problem
> > -----------
> > After the routine runs, I look at the style names, and the aliases
> > have vanished from all but two of the headings!  Seriously!  What I
> > get is:

> > Heading 1
> > Heading 2,PRJ_Heading Level 2
> > Heading 3
> > Heading 4
> > Heading 5
> > Heading 6
> > Heading 7
> > Heading 8,PRJ_Heading Level 8
> > Heading 9

> > What I _should_ get is:

> > Heading 1,PRJ_Heading Level 1
> > Heading 2,PRJ_Heading Level 2
> > Heading 3,PRJ_Heading Level 3
> > Heading 4,PRJ_Heading Level 4
> > Heading 5,PRJ_Heading Level 5
> > Heading 6,PRJ_Heading Level 6
> > Heading 7,PRJ_Heading Level 7
> > Heading 8,PRJ_Heading Level 8
> > Heading 9,PRJ_Heading Level 9

> > The styles seem to function, and I do get the expected heading and
> > numbering behaviour.  But the appearance is not at all what they
> > require, and more importantly, I'm worried it might be indiciative of
> > something more serious.

> > Thanks in advance for your thoughts!

> > Neman Syed



Thu, 10 Feb 2005 06:28:38 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Styles defined in VBA lose their shortcuts (aliases) - but not always - addendum

2. Digital certificate is always lost when saving VBA project

3. Inserting Autotext using VBA - loses formatting and styles

4. How to create a shortcut or alias to the document upon saving the document

5. Problem with Access VBA FTP code -variable not defined error

6. User Defined Type Not Defined

7. User-defined not defined

8. Compile Error: User-defined type not defined

9. Microsoft Visual Basic Compile Error: Uder-defined type not defined

10. User-defined type not defined (Access 97)

11. Excel : User-defined type not define

12. Compile Error - User defined type not defined

 

 
Powered by phpBB® Forum Software