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 / November 2007

Tip: Looking for answers? Try searching our database.

Get all the styles

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Patrick386 - 12 Nov 2007 18:27 GMT
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!
Jay Freedman - 12 Nov 2007 21:15 GMT
"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.

>Hello!
>
[quoted text clipped - 11 lines]
>
>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.
Patrick386 - 13 Nov 2007 08:56 GMT
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

> "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
[quoted text clipped - 28 lines]
> Email cannot be acknowledged; please post all follow-ups to the newsgroup
> so all may benefit.
Jay Freedman - 13 Nov 2007 16:17 GMT
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.

> Ok, but if Word can display it in the Styles & Formating pan, I
> should be able to do it as well..
[quoted text clipped - 36 lines]
>> Email cannot be acknowledged; please post all follow-ups to the
>> newsgroup so all may benefit.
Patrick386 - 13 Nov 2007 16:48 GMT
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?

> 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
[quoted text clipped - 41 lines]
>>> Email cannot be acknowledged; please post all follow-ups to the
>>> newsgroup so all may benefit.
Klaus Linke - 13 Nov 2007 17:24 GMT
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

> 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
[quoted text clipped - 46 lines]
>>>> Email cannot be acknowledged; please post all follow-ups to the
>>>> newsgroup so all may benefit.
Klaus Linke - 13 Nov 2007 17:27 GMT
> Set myC = CommandBars("Formatting").Controls("&Style:")

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

Klaus
Patrick386 - 13 Nov 2007 20:44 GMT
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

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

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

Klaus
Klaus Linke - 13 Nov 2007 21:12 GMT
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 :-)
and good luck to you, too
Klaus

> Hi Klaus!
>
[quoted text clipped - 10 lines]
> anyway thanks and good luck with the styles
> Auf Wiedersehen
profwoman4u2@gmail.com - 13 Nov 2007 23:03 GMT
> > 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?
Patrick386 - 14 Nov 2007 20:44 GMT
Double click on the picture and go to the 'Layout' tab
Select the one you want.

>> > Set myC = CommandBars("Formatting").Controls("&Style:")
>>
[quoted text clipped - 4 lines]
>
> How do your wrap words around a photo?
 
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.