Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop through Word Options

Status
Not open for further replies.

pmcdaniel

Programmer
Feb 9, 2007
127
US
I have a VB 6 app where I would like to loop through all the Options of a Word 2000 object so I can view the values and change where needed. These are Options such as:
AutoFormatAsYouTypeReplaceHyperlinks
AutoFormatReplaceHyperlinks

I'd also like to eventually loop through all the AutoCorrect values but first I want to do the Options.

Code:
Dim AppWd      As Word.Application
Dim objOption  As Word.Options
    
 For Each objOption In AppWd.Options
   Debug.Print [COLOR=red] Value of the Option will be displayed here. [/color]
 Next

When it gets to the "For Each" line the error "Object doesn't support this property or method." is shown. Can someone please tell me how to to do this?

 
More importantly....
Code:
Dim objOption  As Word.Options
    
 For Each objOption In AppWd.Options
You are declaring objOption as if it is a singular object...thus your attempt at For Each objOption...


It is not singular. There is no singular Option object. Thus you can not do a For..Each.

"Value of the Option will be displayed here. "

There is no "the".

You can invoke a direct use of an Option property:

Application.Options.AllowClickAndTypeMouse
Application.Options.AutoFormatAsYouTypeDefineStyles

But you can not do a For...Each on Options, nor can you use an index like Options(3).

Gerry
 
fumei, thanks for confirming what I was afraid of. There are so many options I figured(hoped) there would be some kind of a collection.

 
Well, Options - note the plural - kind of looks like it should be a collection, but it is not really. I can certainly understand how you could have thought that it was a collection. But you can not loop through it, as there is no Option (singular). So, technically, it is ONE object (even though it is plural...go figure) with gobs and gobs of properties. Not a collection. It just kind of looks like it should be a collection.

Just one of the more wonderful oddities of VBA.

BTW: you can get a hint of this structure by looking at Options in the Object Browser. All the listed items are properties. That is, properties of ONE object.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top