Results 1 to 14 of 14
  1. #1
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post

    Finding controls in a form (Word 2003)

    When I type the name of an object followed by a period, auto-complete opens a list of methods and properties defined in it. That list is not complete, though. For example, the object that represents a Font dialog box has a .font property, but auto-complete does not reveal it.

    I wonder if there is some way to get a complete list of an object's properties and methods.

    In particular, I wonder if there is a way to get the names of the controls in a built-in dialog box (like Font).

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Finding controls in a form (Word 2003)

    For your first question, try typing F2 to display the object browser in VBA and search for the object.

    For your question question, try this article on the Word MVPS web site.

    StuartR

  3. #3
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Finding controls in a form (Word 2003)

    Thank you, I've printed the article for later. (I read it on the screen and didn't see what I was looking for, but I want to read it carefully.)

    The Object Browser... I'll try to be nice. I have rarely gotten useful information from VBA's Object Browser, and so rarely try to use it.

    First, there's the question of how to search for an object without knowing its name. VBA can be maddeningly coy about that.

    You create a Font dialog box object in VBA by calling Dialogs(wdDialogFormatFont). What's the type of the value returned? The typename function says it's a Dialog. The O.B. lists the generic members of Dialog. (Auto-complete lists the same set.) Neither one mentions the properties that are belong to a specific dialog box.

    To the extent that VBA is an object-oriented language, Dialog is a superclass, and the names of the subclasses, which I need, are inaccessible.

    But even if the class has no name, I should be able to find its members by creating an instance of it and browsing that, right? Turns out I can't. The O.B. can't find objects created at run time. It's not a true object browser at all; it's just a static object browser. An S.O.B.!

    As it happens, I stumbled across a list of properties for all of the built-in dialog boxes while I was researching this post. it's in Word-VBA's help file, in a topic titled "Built-in Dialog Box Argument Lists," and it reveals the names of all of the dialog box objects' "options." (Argument Lists? Options? Look for help with "properties" or "members" and you'll never find it. Never mind... )

    So now I have an answer to my immediate question. (The answer is that I can't access a built-in dialog box's controls at all, only the current values of the "options" set by the controls. It's not the answer I wanted, but I can stop spending time on it now.)

    The more general problem remains: the S.O.B. does appear to be the only "documentation" for many of the classes in VBA, Word, and the libraries, but it's very incomplete. I've struggled with the problem of "invisible classes" in other contexts before, and I'm sure that I'll have to do so again. I'm still hoping to find a better source of information.

  4. #4
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding controls in a form (Word 2003)

    It's very likely that the Dialog class is a base class (superclass in the parlance of Java) without any public properties. This is consistent with abstract as opposed to concrete classes (like the specific "subclasses" to which you refer). The Dialogs collection contains all the subclasses of specific Dialog types to which you refer.

    > the names of the subclasses, which I need, are inaccessible
    I don't know if it will be of help, but WdWordDialog Enumeration (Microsoft.Office.Interop.Word) contains the enumeration for all of the WdWordDialog types. I think that those relevant to Word 2003 are the same as in Word 2007.

    > Look for help with "properties" or "members" and you'll never find it.
    Again it's likely, since these dialogs are meant to be displayed as standard/ fixed entities, that no (standard) public interface is exposed... except for those items referred to as "options". This non-standard terminology appears to be a hangover from the days of WordBasic (well before VBA) in which the macro language was a long way off an object based structure.

    Alan

  5. #5
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Finding controls in a form (Word 2003)

    >I don't know if it will be of help, but WdWordDialog Enumeration (Microsoft.Office.Interop.Word)
    >contains the enumeration for all of the WdWordDialog types.

    Alas, it doesn't. The members of the Enum (and I think of all VBA Enum's) are just "magic numbers," meaningless to everyone except Dialog.

  6. #6
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Finding controls in a form (Word 2003)

    >> "First, there's the question of how to search for an object without knowing its name. VBA can be maddeningly coy about that."

    Idle curiosity - how would you expect to search for it?

    >>"You create a Font dialog box object in VBA by calling Dialogs(wdDialogFormatFont). What's the type of the value returned? The typename function says it's a Dialog. The O.B. lists the generic members of Dialog. (Auto-complete lists the same set.) Neither one mentions the properties that are belong to a specific dialog box."
    As the TypeName implies, you create a Dialog object. It just happens to be set up to work on Fonts - it's not a FontDialog or some such object. The exposed properties and methods are therefore those of the Dialog class.

    For run-time objects, you can assign them to a variable and use the Locals window to check out properties.

    My personal opinion is pretty much diametrically opposed to yours - I find the OB invaluable, even if on occasion it's just for locating what exactly to search for elsewhere. For anything that is not in there, MSDN is usually a good place to start. (I didn't really get your later comment about the enumeration, I'm afraid.) The OB works off type libraries, which is why it won't give you info about instances of a class that you have created at run-time.

    FWIW
    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Finding controls in a form (Word 2003)

    >> "First, there's the question of how to search for an object without knowing its name....

    >Idle curiosity - how would you expect to search for it?

    The search box in the object browser. The dialog box classes apparently don't have names, though, so it's idle to try to find out what their names are.

    >>"You create a Font dialog box object in VBA by calling Dialogs(wdDialogFormatFont). What's the type of the value returned?...

    >As the TypeName implies, you create a Dialog object. It just happens to be set up to work on Fonts - it's not a FontDialog or some such object.

    I beg to differ. It may not have a name, but it is a distinct class with a unique set of properties -- although one must go to ridiculous lengths to find out what they are.

    >For run-time objects, you can assign them to a variable and use the Locals window to check out properties.

    Interesting. There it is in the menu, and I never even noticed it. It's interesting to poke at stuff like this, and sometimes very useful.

    The Locals window looks useful for exactly what its name suggests -- getting a complete display of a procedure's locals. For inspecting objects, not so useful. I created a Font d.b. object and looked at it in Locals. I got all sorts of interesting stuff, but it concerned the object's parents and environment. The window didn't display the elusive properties -- just same old tired methods that auto-complete shows, and not even all of those.

  8. #8
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Finding controls in a form (Word 2003)

    What is the basis for your assertion that each dialog represents a separate class, rather than being an instance of the Dialog class which is set up dynamically? (Note: you may well be right, I'm just curious as to why you are so sure that something of which you can find no evidence exists)
    Regards,
    Rory

    Microsoft MVP - Excel

  9. #9
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding controls in a form (Word 2003)

    Could you give us an example of what you're wanting to do with a dialog, that the article Stuart pointed to doesn't cover?

    Alan

  10. #10
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Finding controls in a form (Word 2003)

    rory wrote: "What is the basis for your assertion that each dialog represents a separate class, rather than being an instance of the Dialog class which is set up dynamically?"

    In my world, a type of object with a distinct set of properties and methods is a class, by definition. Whether it is defined dynamically or not is incidental. (In a language like VBA, the meaning of "dynamically" is doubtful in any case; the compiler doesn't do much more than check syntax, so in a sense you mean, practically everything is dynamic.)

    AlanMiller wrote: "Could you give us an example of what you're wanting to do with a dialog, that the article Stuart pointed to doesn't cover?"

    I wanted to gain access to the controls in a built-in dialog box -- something which I'm now persuaded is impossible in VBA.

    I wanted to make the standard Font dialog box work a little differently than it ordinarily does. It now appears that I would have to find open source equivalents of the color palette and underline selector and roll my own DLL.

  11. #11
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding controls in a form (Word 2003)

    Here ya go. It's only a handful of code and shouldn't be too hard to set up as a class, OCX or whatever you're after.

    Alan
    Attached Files Attached Files

  12. #12
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Finding controls in a form (Word 2003)

    So if I have a form that adds different controls at runtime, each different instance of the form becomes a new class? (that is what I meant by dynamically)
    Regards,
    Rory

    Microsoft MVP - Excel

  13. #13
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Finding controls in a form (Word 2003)

    AlanMiller wrote: "Here ya go. It's only a handful of code and shouldn't be too hard to set up as a class, OCX or whatever you're after."

    Thank you. I won't have time to look at it until later this weekend, but it should be a big help.

    Rory wrote: "So if I have a form that adds different controls at runtime, each different instance of the form becomes a new class?"

    I have never done that, so my answer is based on some quick web research, but in VBA, I don't think so. Adding a control to a form does not add methods or properties to the class. If it did, you would have a new class.

    My answer is based on the following, which I found at http://pubs.logicalexpressions.com/pub0009...cle.asp?ID=259:

    <hr>Now later on in your code, if you want to refer to the newly added control, but you no longer have the myLabel reference, you can either use:

    frmMyForm.Controls("lblPrompt”)

    or

    frmMyForm!lblPrompt

    You cannot use the other syntax to refer to a control:

    frmMyform.lblPrompt<hr>

  14. #14
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Finding controls in a form (Word 2003)

    That article is not entirely correct - you can refer to controls that way - it just depends on what interface you declared for your variable. I would also take issue with your idea of it being a class, since it would only be that particular instance that had the properties and you couldn't then create a new instance of the "new class".
    Regardless, I don't think any of this helps with your issue, which Alan has now solved so I think we'll agree to disagree.
    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •