Computer Forum Forum Index
Register  FAQ Profile Log in to check your private messages Log in Register 

Get all the styles

 
Post new topic   Reply to topic    Computer Forum Forum Index -> microsoft word vba beginners
View previous topic :: View next topic  
Author Message
Patrick386
Guest





PostPosted: Mon Nov 12, 2007 6:27 pm    Post subject: Get all the styles Reply with quote

Hello!

How come that when I loop on a document's styles, I do not find all the styles as they are displayed in the Styles and Fomratting pan?
for instance if the user applyes the style "Normal" and then changes the alignment or the font color, the pan displays:
"Normal"
"Normal + Center"

but when I make loop on all the styles existing in the document, I only see "Normal"?
For i=1 to ThisDocument.Styles.Count
msgBox ThisDocument.Styles(i).NameLocal
Next i

How can get all of them?

Thanks in advance for any suggestion!
Back to top
Google
Sponsor





PostPosted: Mon Nov 12, 2007 6:27 pm    Post subject: Advertisement

Back to top
Jay Freedman
Guest





PostPosted: Mon Nov 12, 2007 9:15 pm    Post subject: Re: Get all the styles Reply with quote

"Normal + Center" is _not_ a style, in the sense that it isn't a
member of the Styles collection. It's the result -- in the user
interface only -- of having the "Keep track of formatting" option set.
That option causes Word to display each application of direct
formatting as a separate choice in the panel so you can use the
"select all instances" button. VBA doesn't know anything about it.

On Mon, 12 Nov 2007 19:27:40 +0100, "Patrick386"
<patrick386@hotmail.com> wrote:

Quote:
Hello!

How come that when I loop on a document's styles, I do not find all the styles as they are displayed in the Styles and Fomratting pan?
for instance if the user applyes the style "Normal" and then changes the alignment or the font color, the pan displays:
"Normal"
"Normal + Center"

but when I make loop on all the styles existing in the document, I only see "Normal"?
For i=1 to ThisDocument.Styles.Count
msgBox ThisDocument.Styles(i).NameLocal
Next i

How can get all of them?

Thanks in advance for any suggestion!

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
Back to top
Patrick386
Guest





PostPosted: Tue Nov 13, 2007 8:56 am    Post subject: Re: Get all the styles Reply with quote

Ok, but if Word can display it in the Styles & Formating pan, I should be
able to do it as well..
I understand that it's not a style. but then, is there a collection of the
format tracking? because it's automatically displayed, it must be stored
somewhere..

Thanks again

"Jay Freedman" <jay.freedman@verizon.net> a écrit dans le message de news:
rdghj398ekas7l7k26p9ri0v6a4cjj8uog@4ax.com...
Quote:
"Normal + Center" is _not_ a style, in the sense that it isn't a
member of the Styles collection. It's the result -- in the user
interface only -- of having the "Keep track of formatting" option set.
That option causes Word to display each application of direct
formatting as a separate choice in the panel so you can use the
"select all instances" button. VBA doesn't know anything about it.

On Mon, 12 Nov 2007 19:27:40 +0100, "Patrick386"
patrick386@hotmail.com> wrote:

Hello!

How come that when I loop on a document's styles, I do not find all the
styles as they are displayed in the Styles and Fomratting pan?
for instance if the user applyes the style "Normal" and then changes the
alignment or the font color, the pan displays:
"Normal"
"Normal + Center"

but when I make loop on all the styles existing in the document, I only
see "Normal"?
For i=1 to ThisDocument.Styles.Count
msgBox ThisDocument.Styles(i).NameLocal
Next i

How can get all of them?

Thanks in advance for any suggestion!

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup
so all may benefit.
Back to top
Jay Freedman
Guest





PostPosted: Tue Nov 13, 2007 4:17 pm    Post subject: Re: Get all the styles Reply with quote

It may be "stored somewhere" but the "somewhere" is not accessible to VBA;
or it may be generated on the fly in the user interface. The sad fact is
that there are a great many things that Word obviously "knows" but doesn't
make available to VBA. This is one of them.

Patrick386 wrote:
Quote:
Ok, but if Word can display it in the Styles & Formating pan, I
should be able to do it as well..
I understand that it's not a style. but then, is there a collection
of the format tracking? because it's automatically displayed, it must
be stored somewhere..

Thanks again

"Jay Freedman" <jay.freedman@verizon.net> a écrit dans le message de
news: rdghj398ekas7l7k26p9ri0v6a4cjj8uog@4ax.com...
"Normal + Center" is _not_ a style, in the sense that it isn't a
member of the Styles collection. It's the result -- in the user
interface only -- of having the "Keep track of formatting" option
set. That option causes Word to display each application of direct
formatting as a separate choice in the panel so you can use the
"select all instances" button. VBA doesn't know anything about it.

On Mon, 12 Nov 2007 19:27:40 +0100, "Patrick386"
patrick386@hotmail.com> wrote:

Hello!

How come that when I loop on a document's styles, I do not find all
the styles as they are displayed in the Styles and Fomratting pan?
for instance if the user applyes the style "Normal" and then
changes the alignment or the font color, the pan displays:
"Normal"
"Normal + Center"

but when I make loop on all the styles existing in the document, I
only see "Normal"?
For i=1 to ThisDocument.Styles.Count
msgBox ThisDocument.Styles(i).NameLocal
Next i

How can get all of them?

Thanks in advance for any suggestion!

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
Back to top
Patrick386
Guest





PostPosted: Tue Nov 13, 2007 4:48 pm    Post subject: Re: Get all the styles Reply with quote

I'm still not sure that you cannot have the list of the format changes. it's
not because I can't get it, that it doesn't exist.. it would be the 1st time
that I would see that
Do you have an example of a function that you have in Word and not in Vba?

"Jay Freedman" <jay.freedman@verizon.net> a écrit dans le message de news:
OQTf3ChJIHA.4584@TK2MSFTNGP03.phx.gbl...
Quote:
It may be "stored somewhere" but the "somewhere" is not accessible to VBA;
or it may be generated on the fly in the user interface. The sad fact is
that there are a great many things that Word obviously "knows" but doesn't
make available to VBA. This is one of them.

Patrick386 wrote:
Ok, but if Word can display it in the Styles & Formating pan, I
should be able to do it as well..
I understand that it's not a style. but then, is there a collection
of the format tracking? because it's automatically displayed, it must
be stored somewhere..

Thanks again

"Jay Freedman" <jay.freedman@verizon.net> a écrit dans le message de
news: rdghj398ekas7l7k26p9ri0v6a4cjj8uog@4ax.com...
"Normal + Center" is _not_ a style, in the sense that it isn't a
member of the Styles collection. It's the result -- in the user
interface only -- of having the "Keep track of formatting" option
set. That option causes Word to display each application of direct
formatting as a separate choice in the panel so you can use the
"select all instances" button. VBA doesn't know anything about it.

On Mon, 12 Nov 2007 19:27:40 +0100, "Patrick386"
patrick386@hotmail.com> wrote:

Hello!

How come that when I loop on a document's styles, I do not find all
the styles as they are displayed in the Styles and Fomratting pan?
for instance if the user applyes the style "Normal" and then
changes the alignment or the font color, the pan displays:
"Normal"
"Normal + Center"

but when I make loop on all the styles existing in the document, I
only see "Normal"?
For i=1 to ThisDocument.Styles.Count
msgBox ThisDocument.Styles(i).NameLocal
Next i

How can get all of them?

Thanks in advance for any suggestion!

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

Back to top
Klaus Linke
Guest





PostPosted: Tue Nov 13, 2007 5:24 pm    Post subject: Re: Get all the styles Reply with quote

You could get the strings that are displayed from the Styles control:

Dim myC As CommandBarComboBox
Dim i As Long
Set myC = CommandBars("Formatting").Controls("&Style:")
With myC
For i = 1 To .ListCount
Debug.Print myC.List(i)
Next i
End With

(not sure if "&Style:" is the correct caption... You can use the index of the styles control on the toolbar instead.)

It's still a good distance from getting those strings to translating them to something you can use in your code to actually, say, search for that combination of style and formatting.
Plus, it'll only work in one specific language version (... a drawback for me, since I work with both the Engish and German version on different machines).

Like you, I'd regard the ability to get directly at these formatting pseudo-styles as a major improvement, and have asked for it a few times.

As far as I understand it, they are stored pretty much the same way as styles are stored.
On the other hand, Word itself has a terrible time selecting "all instances" of some formatting.

On a large document, Word typically spends minutes analyzing the doc, whereas when I search for that style and formatting directly, it'll find it much, much faster.
So I think there's some pretty basic problem either with my understanding of how Word works, or with the implementation.
If formatting is really stored much the same way as a style, Word should be able to locate all instances where that formatting was used very quickly.
On the other hand, the styles and formatting pane often lists styles and manual formatting that only existed in the documents hours ago.
So it seems as if Word may not in fact have any way to look the list of "pseudo-styles" up quickly, or at least not reliably.

Regards,
Klaus




"Patrick386" <patrick386@hotmail.com> wrote:
Quote:
I'm still not sure that you cannot have the list of the format changes. it's
not because I can't get it, that it doesn't exist.. it would be the 1st time
that I would see that
Do you have an example of a function that you have in Word and not in Vba?

"Jay Freedman" <jay.freedman@verizon.net> a écrit dans le message de news:
OQTf3ChJIHA.4584@TK2MSFTNGP03.phx.gbl...
It may be "stored somewhere" but the "somewhere" is not accessible to VBA;
or it may be generated on the fly in the user interface. The sad fact is
that there are a great many things that Word obviously "knows" but doesn't
make available to VBA. This is one of them.

Patrick386 wrote:
Ok, but if Word can display it in the Styles & Formating pan, I
should be able to do it as well..
I understand that it's not a style. but then, is there a collection
of the format tracking? because it's automatically displayed, it must
be stored somewhere..

Thanks again

"Jay Freedman" <jay.freedman@verizon.net> a écrit dans le message de
news: rdghj398ekas7l7k26p9ri0v6a4cjj8uog@4ax.com...
"Normal + Center" is _not_ a style, in the sense that it isn't a
member of the Styles collection. It's the result -- in the user
interface only -- of having the "Keep track of formatting" option
set. That option causes Word to display each application of direct
formatting as a separate choice in the panel so you can use the
"select all instances" button. VBA doesn't know anything about it.

On Mon, 12 Nov 2007 19:27:40 +0100, "Patrick386"
patrick386@hotmail.com> wrote:

Hello!

How come that when I loop on a document's styles, I do not find all
the styles as they are displayed in the Styles and Fomratting pan?
for instance if the user applyes the style "Normal" and then
changes the alignment or the font color, the pan displays:
"Normal"
"Normal + Center"

but when I make loop on all the styles existing in the document, I
only see "Normal"?
For i=1 to ThisDocument.Styles.Count
msgBox ThisDocument.Styles(i).NameLocal
Next i

How can get all of them?

Thanks in advance for any suggestion!

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.



Back to top
Klaus Linke
Guest





PostPosted: Tue Nov 13, 2007 5:27 pm    Post subject: Re: Get all the styles Reply with quote

Quote:
Set myC = CommandBars("Formatting").Controls("&Style:")

or using the control's Id:
Set myC = CommandBars.FindControl(ID:=1732)

Klaus
Back to top
Patrick386
Guest





PostPosted: Tue Nov 13, 2007 8:44 pm    Post subject: Re: Get all the styles Reply with quote

Hi Klaus!

Great thanks for your help and the time you've spent on the question!!
That's true about the time that Word takes to list the fomatting list.. I
was wondering if may be, it doesn't scann the whole document and look for
'modified' styles (formats) and keep them in memory and then keep traking of
it if the user makes any changes.

but the liste is displayed so fast once the document open. it is displayed
in the pan, in the Find & Replace: when you choose a style, it shows
imediatly of what the format or style is composed of..

anyway thanks and good luck with the styles
Auf Wiedersehen


"Klaus Linke" <info@fotosatz-kaufmann.de> a écrit dans le message de news:
%23OMuHqhJIHA.1204@TK2MSFTNGP03.phx.gbl...
Quote:
Set myC = CommandBars("Formatting").Controls("&Style:")

or using the control's Id:
Set myC = CommandBars.FindControl(ID:=1732)

Klaus
Back to top
Klaus Linke
Guest





PostPosted: Tue Nov 13, 2007 9:12 pm    Post subject: Re: Get all the styles Reply with quote

Yes, something like that probably, tracking back through all the changes that were made to consolidate the list.
But my feeling is that someone just implemented it in a hurry, and that it shouldn't need to take nearly as long.

Which is a shame, since if the pane often lists formatting that does not really exist, it diminishes the value of the pane.
And if you have to wait a few minutes for Word to analyze the document and select all instances of some formatting, people will avoid this in principle great feature.

I've never actually tried to exploit the list of (style+manual) formatting that can be acquired with the macro I posted. Now that you've reminded me of the possibility, maybe I'll give it a run.

So... Danke schön Smile
and good luck to you, too
Klaus




"Patrick386" <patrick386@hotmail.com> wrote:
Quote:
Hi Klaus!

Great thanks for your help and the time you've spent on the question!!
That's true about the time that Word takes to list the fomatting list.. I
was wondering if may be, it doesn't scann the whole document and look for
'modified' styles (formats) and keep them in memory and then keep traking of
it if the user makes any changes.

but the liste is displayed so fast once the document open. it is displayed
in the pan, in the Find & Replace: when you choose a style, it shows
imediatly of what the format or style is composed of..

anyway thanks and good luck with the styles
Auf Wiedersehen
Back to top
Guest






PostPosted: Tue Nov 13, 2007 11:03 pm    Post subject: Re: Get all the styles Reply with quote

On Nov 13, 9:27 am, "Klaus Linke" <i...@fotosatz-kaufmann.de> wrote:
Quote:
Set myC = CommandBars("Formatting").Controls("&Style:")

or using the control's Id:
Set myC = CommandBars.FindControl(ID:=1732)

Klaus

How do your wrap words around a photo?
Back to top
Patrick386
Guest





PostPosted: Wed Nov 14, 2007 8:44 pm    Post subject: Re: Get all the styles Reply with quote

Double click on the picture and go to the 'Layout' tab
Select the one you want.


<profwoman4u2@gmail.com> a écrit dans le message de news:
1194995021.555012.220500@o80g2000hse.googlegroups.com...
Quote:
On Nov 13, 9:27 am, "Klaus Linke" <i...@fotosatz-kaufmann.de> wrote:
Set myC = CommandBars("Formatting").Controls("&Style:")

or using the control's Id:
Set myC = CommandBars.FindControl(ID:=1732)

Klaus

How do your wrap words around a photo?
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Computer Forum Forum Index -> microsoft word vba beginners All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Computer Forum