Remove a Character style from a Paragraph style - i.e., undo Linked style

D

dedawson

I have a paragraph style that has somehow managed to become a 'linked'
style. Is there a VBA means of undoing this?

I have poked around through the object reference and found how to set
such a link; e.g.,
ActiveDocument.Styles("Heading 1").LinkStyle = ActiveDocument.Styles
("Heading 1 Characters")

Unfortunately, I have been unable to figure out how to undo such an
action.
 
S

Stefan Blom

See http://homepage.hispeed.ch/cindymeister/MyFavTip.htm#CharStyl.

Stefan Blom
Microsoft Word MVP


"dedawson" wrote in message

I have a paragraph style that has somehow managed to become a 'linked'
style. Is there a VBA means of undoing this?

I have poked around through the object reference and found how to set
such a link; e.g.,
ActiveDocument.Styles("Heading 1").LinkStyle = ActiveDocument.Styles
("Heading 1 Characters")

Unfortunately, I have been unable to figure out how to undo such an
action.
 
D

dedawson

Gave Cindy's approach a shot, but no success.

Sub DeleteHeading2Char()
Dim styl As Word.Style, doc As Word.Document
Set doc = ActiveDocument
Set styl = doc.Styles.Add(Name:="Style1")
On Error Resume Next
doc.Styles("P0 Char").LinkStyle = styl
styl.Delete
End Sub

Looking at her code, it appears that the idea is to link a newly
created dummy Paragraph style (Style1) to the Character style in
question, thereby breaking the Character style's association with its
original Paragraph style. Then when the dummy Paragraph style is
deleted, it will delete the newly associated Character style that one
wants to get rid of.

The problem I have is that the line:

doc.Styles("Heading 2 Char").LinkStyle = styl

will not actually make the new association; the original LinkStyle is
retained. If one comments out the On Error, one can see that the
dummy Style1 is not valid for use as a LinkStyle.

Checking associations via Immediate window give same results both
before and after execution of code.

?ActiveDocument.Styles("P0").linkstyle => P0 Char
?ActiveDocument.Styles("P0 Char").linkstyle => P0


Any further thoughts?

david
 
D

dedawson

Gave Cindy's approach a shot, but no success. BTW, I'm attempting
this under Word 2007.

Sub DeleteHeading2Char()
Dim styl As Word.Style, doc As Word.Document
Set doc = ActiveDocument
Set styl = doc.Styles.Add(Name:="Style1")
On Error Resume Next
doc.Styles("P0 Char").LinkStyle = styl
styl.Delete
End Sub

Looking at her code, it appears that the idea is to link a newly
created dummy Paragraph style (Style1) to the Character style in
question, thereby breaking the Character style's association with its
original Paragraph style. Then when the dummy Paragraph style is
deleted, it will delete the newly associated Character style that one
wants to get rid of.

The problem I have is that the line:

doc.Styles("Heading 2 Char").LinkStyle = styl

will not actually make the new association; the original LinkStyle is
retained. If one comments out the On Error, one can see that the
dummy Style1 is not valid for use as a LinkStyle.

Checking associations via Immediate window give same results both
before and after execution of code.

?ActiveDocument.Styles("P0").linkstyle => P0 Char
?ActiveDocument.Styles("P0 Char").linkstyle => P0

Any further thoughts?

david
 
S

Stefan Blom

Does it make a difference if the LinkStyle is a CHARACTER style?

Actually, in a quick test, it doesn't seem to work with a character style
either. :-(

Stefan Blom
Microsoft Word MVP


"dedawson" wrote in message

Gave Cindy's approach a shot, but no success. BTW, I'm attempting
this under Word 2007.

Sub DeleteHeading2Char()
Dim styl As Word.Style, doc As Word.Document
Set doc = ActiveDocument
Set styl = doc.Styles.Add(Name:="Style1")
On Error Resume Next
doc.Styles("P0 Char").LinkStyle = styl
styl.Delete
End Sub

Looking at her code, it appears that the idea is to link a newly
created dummy Paragraph style (Style1) to the Character style in
question, thereby breaking the Character style's association with its
original Paragraph style. Then when the dummy Paragraph style is
deleted, it will delete the newly associated Character style that one
wants to get rid of.

The problem I have is that the line:

doc.Styles("Heading 2 Char").LinkStyle = styl

will not actually make the new association; the original LinkStyle is
retained. If one comments out the On Error, one can see that the
dummy Style1 is not valid for use as a LinkStyle.

Checking associations via Immediate window give same results both
before and after execution of code.

?ActiveDocument.Styles("P0").linkstyle => P0 Char
?ActiveDocument.Styles("P0 Char").linkstyle => P0

Any further thoughts?

david
 
D

dedawson

After poking around a bit more, I have concluded that MS has either
accidentally, or intentionally, removed the ability to delink
paragraph and character styles in Word 2007.

Here’s how I have come to this conclusion.

I have always built my templates programmatically (since Word 97,
based upon techniques presented by various Word MVPs) in order to
avoid the spaghetti numbering issues that have been with Word for so
long. Part of that code included the statements to define new styles,
including their type.

e.g., ActiveDocument.Styles.Add Name:="P0", Type:=wdStyleTypeParagraph

Executing this code in 2003 would result in the creation of a style
that was indeed a pure paragraph style. When viewed in the Styles
Inspector dialog, style P0 would show only the ¶, and when viewed in
the Modify Style dialog the Style Type is given as Paragraph and is
the dropdown is enabled for modification. If an associated Character
style, P0 Char, were to be subsequently generated by the application
of direct character formatting to a subset of the characters within a
P0 paragraph, one could programmatically unlink the two styles (using
code provided at http://oreilly.com/pub/h/2597 ) (it worked well; I
used it often)

Executing this code in 2007, however, provides different results.
When viewed in the Styles Inspector dialog style P0 is shown as ¶a,
and when viewed in the Modify Style dialog the Style Type is given as
Linked (paragraph and character) and is grayed out. The O’Reilly
code will not, however, unlink these two styles.

Further investigation reveals Word 2007 has an additional enumeration
for WdStyleType, that being wdStyleTypeParagraphOnly

Execution of ActiveDocument.Styles.Add Name:="P0",
Type:=wdStyleTypeParagraphOnly will result in the definition of a
style that was indeed a pure paragraph style. When viewed in the
Styles Inspector dialog, style P0 would show only the ¶, and when
viewed in the Modify Style dialog the Style Type is given as Paragraph
and is enabled for modification.

Here’s where it gets nasty, however. If one uses the 2007 Modify
Paragraph dialog to change the type of the P0 style from Paragraph to
Linked (paragraph and character), there is no turning back. The P0
Char style gets created, and the Style Type dropdown in the Modify
Styles dialog gets disabled.

Decided to go a little further, and recorded a macro while I used the
Modify Style dialog to modify the Style Type from Paragraph to Linked
(paragraph and character). Examination of the code that is generated
reveals that whatever is being done to effect the change does not get
recorded as code. Lovely.

But remember, using Type:=wdStyleTypeParagraphOnly does allow one to
create a pure Paragraph style. Now all one needs to do is prevent it
from being converted to a Linked paragraph style. Guess what?
The .locked attribute that one would expect to preclude changes
apparently has no effect. About the only means of preventing creation
of a pair of Linked paragraph and character styles is to enable
Disable Linked Styles in the Styles Inspector dialog. But, since
there does not appear to be any means of locking this into place, a
user could disable it, and the end up creating Linked styles.

In summary, it would appear that the ability to create bullet-proof
templates with auto-numbered styles has been broken. If anyone has
any further light to shed on this, I'm sure it would be welcomed by
many.
 
D

dedawson

After poking around a bit more, I have concluded that MS has either
accidentally, or intentionally, removed the ability to delink
paragraph and character styles in Word 2007.

Here’s how I have come to this conclusion.

I have always built my templates programmatically (since Word 97,
based upon techniques presented by various Word MVPs) in order to
avoid the spaghetti numbering issues that have been with Word for so
long. Part of that code included the statements to define new styles,
including their type.

e.g., ActiveDocument.Styles.Add Name:="P0", Type:=wdStyleTypeParagraph

Executing this code in 2003 would result in the creation of a style
that was indeed a pure paragraph style. When viewed in the Styles
task pane, style P0 would show only the ¶, and when viewed in the
Modify Style dialog the Style Type is given as Paragraph and is the
dropdown is enabled for modification. If an associated Character
style, P0 Char, were to be subsequently generated by the application
of direct character formatting to a subset of the characters within a
P0 paragraph, one could programmatically unlink the two styles (using
code provided at http://oreilly.com/pub/h/2597 ) (it worked well; I
used it often)

Executing this code in 2007, however, provides different results.
When viewed in the Styles task pane dialog style P0 is shown as ¶a,
and when viewed in the Modify Style dialog the Style Type is given as
Linked (paragraph and character) and is grayed out. The O’Reilly
code will not, however, unlink these two styles.

Further investigation reveals Word 2007 has an additional enumeration
for WdStyleType, that being wdStyleTypeParagraphOnly

Execution of ActiveDocument.Styles.Add Name:="P0",
Type:=wdStyleTypeParagraphOnly will result in the definition of a
style that was indeed a pure paragraph style. When viewed in the
Styles task pane dialog, style P0 would show only the ¶, and when
viewed in the Modify Style dialog the Style Type is given as Paragraph
and is enabled for modification.

Here’s where it gets nasty, however. If one uses the 2007 Modify
Paragraph dialog to change the type of the P0 style from Paragraph to
Linked (paragraph and character), there is no turning back. The P0
Char style gets created, and the Style Type dropdown in the Modify
Styles dialog gets disabled.

Decided to go a little further, and recorded a macro while I used the
Modify Style dialog to modify the Style Type from Paragraph to Linked
(paragraph and character). Examination of the code that is generated
reveals that whatever is being done to effect the change does not get
recorded as code. Lovely.

But remember, using Type:=wdStyleTypeParagraphOnly does allow one to
create a pure Paragraph style. Now all one needs to do is prevent it
from being converted to a Linked paragraph style. Guess what?
The .locked attribute that one would expect to preclude changes
apparently has no effect. About the only means of preventing creation
of a pair of Linked paragraph and character styles is to enable
Disable Linked Styles in the Styles task pane. But, since there does
not appear to be any means of locking this into place, a user could
disable it, and the end up creating Linked styles.

In summary, it would appear that the ability to create bullet-proof
templates with auto-numbered styles has been broken. If anyone has
any further light to shed on this, I’m sure it would be welcomed by
many.
 
S

Stefan Blom

Thank you for your "detective work" in this area!

Note that there is a setting in the Styles pane to prevent the use of linked
styles. I'm wondering if that could be relevant for your discoveries?

Stefan Blom
Microsoft Word MVP


"dedawson" wrote in message

After poking around a bit more, I have concluded that MS has either
accidentally, or intentionally, removed the ability to delink
paragraph and character styles in Word 2007.

Here’s how I have come to this conclusion.

I have always built my templates programmatically (since Word 97,
based upon techniques presented by various Word MVPs) in order to
avoid the spaghetti numbering issues that have been with Word for so
long. Part of that code included the statements to define new styles,
including their type.

e.g., ActiveDocument.Styles.Add Name:="P0", Type:=wdStyleTypeParagraph

Executing this code in 2003 would result in the creation of a style
that was indeed a pure paragraph style. When viewed in the Styles
task pane, style P0 would show only the ¶, and when viewed in the
Modify Style dialog the Style Type is given as Paragraph and is the
dropdown is enabled for modification. If an associated Character
style, P0 Char, were to be subsequently generated by the application
of direct character formatting to a subset of the characters within a
P0 paragraph, one could programmatically unlink the two styles (using
code provided at http://oreilly.com/pub/h/2597 ) (it worked well; I
used it often)

Executing this code in 2007, however, provides different results.
When viewed in the Styles task pane dialog style P0 is shown as ¶a,
and when viewed in the Modify Style dialog the Style Type is given as
Linked (paragraph and character) and is grayed out. The O’Reilly
code will not, however, unlink these two styles.

Further investigation reveals Word 2007 has an additional enumeration
for WdStyleType, that being wdStyleTypeParagraphOnly

Execution of ActiveDocument.Styles.Add Name:="P0",
Type:=wdStyleTypeParagraphOnly will result in the definition of a
style that was indeed a pure paragraph style. When viewed in the
Styles task pane dialog, style P0 would show only the ¶, and when
viewed in the Modify Style dialog the Style Type is given as Paragraph
and is enabled for modification.

Here’s where it gets nasty, however. If one uses the 2007 Modify
Paragraph dialog to change the type of the P0 style from Paragraph to
Linked (paragraph and character), there is no turning back. The P0
Char style gets created, and the Style Type dropdown in the Modify
Styles dialog gets disabled.

Decided to go a little further, and recorded a macro while I used the
Modify Style dialog to modify the Style Type from Paragraph to Linked
(paragraph and character). Examination of the code that is generated
reveals that whatever is being done to effect the change does not get
recorded as code. Lovely.

But remember, using Type:=wdStyleTypeParagraphOnly does allow one to
create a pure Paragraph style. Now all one needs to do is prevent it
from being converted to a Linked paragraph style. Guess what?
The .locked attribute that one would expect to preclude changes
apparently has no effect. About the only means of preventing creation
of a pair of Linked paragraph and character styles is to enable
Disable Linked Styles in the Styles task pane. But, since there does
not appear to be any means of locking this into place, a user could
disable it, and the end up creating Linked styles.

In summary, it would appear that the ability to create bullet-proof
templates with auto-numbered styles has been broken. If anyone has
any further light to shed on this, I’m sure it would be welcomed by
many.
 
D

dedawson

The setting is "Disable Linked Styles", discussed in the next to last
paragraph of my prior post. Helps, but does not entirely solve the
problem.
 
S

Stefan Blom

OK, I overlooked that (reading too quickly, apparently). :-(

Stefan Blom
Microsoft Word MVP


"dedawson" wrote in message

The setting is "Disable Linked Styles", discussed in the next to last
paragraph of my prior post. Helps, but does not entirely solve the
problem.
 

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