JB said:
OK Folks Help required....I just can't seem to think this through.
I have 7 toolbars, in each of the toolbars there are between 9 and 14
controls. For each of the controls I want to extract data which may be
up to 22 items.
How the hell can I do this using an array/arrays???
I've tried to do this using dynamic arrays but with no success.
Any pointers??
Cheers
J
No, no pointers: this is a VBA newsgroup, not a C/C++ newsgroup. ;-)
I wouldn't recommend using arrays at all. Rather, either create your own objects to store the data using VBA classes (the best solution), or use collections, like so:
Sub SaveCommandBars()
Dim CmdBar As CommandBar
Dim Control As CommandBarControl
Dim Toolbars As Collection
Dim Toolbar As Collection
Set Toolbars = New Collection
For Each CmdBar In Application.CommandBars
If CmdBar.BuiltIn = False Then
Set Toolbar = New Collection
For Each Control In CmdBar.Controls
Call Toolbar.Add(Control.Application, "Application")
'... add all the other items you want
Next Control
Call Toolbars.Add(Toolbar, CmdBar.Name)
End If
Next CmdBar
End Sub
I'm adding each property explicitly because I don't know of a way to iterate through a Control's properties; but I'm sure it can be done somehow, possibly by casting it to some generic type. Or perhaps that's the Java in me speaking.
Referencing your previous posts, if the purpose of this is to add the info to an ini file, perhaps you should forget storing the information and just create the ini file as you iterate through the controls.
-Peter