Loop through all properties

J

jb

Hi Folks,
I'm looking for a way to loop through all the properties of a Style (and
maybe other objects in word) so that I can strip out everything and read
the settings placed on them.

i.e. For Each oProp in Activedocuemnt.style("Stylename")
astrMyProp(i) = oProp
Next


Cheers

J
 
J

Jay Freedman

jb said:
Hi Folks,
I'm looking for a way to loop through all the properties of a Style
(and maybe other objects in word) so that I can strip out everything
and read the settings placed on them.

i.e. For Each oProp in Activedocuemnt.style("Stylename")
astrMyProp(i) = oProp
Next


Cheers

J

Hi jb,

Sorry, there is no such collection to loop through. Even if there were, the
properties aren't all simple strings and numbers -- some of them are objects
with their own sets of properties, some of which are objects, ad nauseam.

As an interesting experiment, use F5 in the VBA editor to run this macro:

Public Sub FooBar()
Dim oStyle As Style
Set oStyle = ActiveDocument.Styles("Normal")
Stop
End Sub

When the execution reaches the Stop statement, right-click the word oStyle
and select Add Watch, then click OK in the dialog. In the Watch window,
click the plus sign next to oStyle to display all the properties of the
Style object. The ones that have their own plus signs are objects, and you
can expand them to see their properties, and so on into the 'hall of
mirrors'.

You'll have to write explicit code to extract the properties you're
interested in.
 
J

jb

Jay said:
Hi jb,

Sorry, there is no such collection to loop through. Even if there were, the
properties aren't all simple strings and numbers -- some of them are objects
with their own sets of properties, some of which are objects, ad nauseam.

As an interesting experiment, use F5 in the VBA editor to run this macro:

Public Sub FooBar()
Dim oStyle As Style
Set oStyle = ActiveDocument.Styles("Normal")
Stop
End Sub

When the execution reaches the Stop statement, right-click the word oStyle
and select Add Watch, then click OK in the dialog. In the Watch window,
click the plus sign next to oStyle to display all the properties of the
Style object. The ones that have their own plus signs are objects, and you
can expand them to see their properties, and so on into the 'hall of
mirrors'.

You'll have to write explicit code to extract the properties you're
interested in.
Hi Jay,

That's what I feared. I have already done this but as with all things
you write to help people it's never quite got all the things they want.
I just wanted to solve problems this time round before they asked for
them :)

Thanks

J
 
K

Klaus Linke

Getting all the properties and methods from any object would be really neat.
Same for comparing all properties from one object with those of another object of the same class (If myStyle1.Font = myStyle2.Font Then).
Anyone knows if they added something like that to VB.Net?

Regards,
Klaus
 

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