PDA

View Full Version : Can I use the Add 'Before' and 'After' arguments for CustomDocumentProperties ?



avi10000
01-20-2013, 11:14 AM
Hi all,

Is there any way that I can use the 'Before' and 'After' arguments for the Add() method of the CustomDocumentProperties collection?

According to the documentation following below, I should be able to, since CustomDocumentProperties is a collection and assume it should inherit the 'Before' and 'After' properties. But although the VBA syntax allows me to add something like 'Before:=2',

However, at run-time this causes an error.

TIA

Avraham


Add Method (Visual Basic for Applications)

Adds a member to a Collection object.

Syntax

object.Add item, key, before, after

The Add method syntax has the following object qualifier and named arguments:

Part Description

object Required. An object expression that evaluates to an object in the Applies To list.

item Required. An expression of any type that specifies the member to add to the collection.

key Optional. A unique string expression that specifies a key string that can be used, instead of a positional index, to access a member of the collection.

before Optional. An expression that specifies a relative position in the collection. The member to be added is placed in the collection before the member identified by the before argument. If anumeric expression, before must be a number from 1 to the value of the collection's Countproperty. If a string expression, before must correspond to the key specified when the member being referred to was added to the collection. You can specify a before position or an afterposition, but not both.

after Optional. An expression that specifies a relative position in the collection. The member to be added is placed in the collection after the member identified by the after argument. If numeric,after must be a number from 1 to the value of the collection's Count property. If a string, aftermust correspond to the key specified when the member referred to was added to the collection. You can specify a before position or an after position, but not both.

fumei
01-20-2013, 01:53 PM
"object Required. An object expression that evaluates to an object in the Applies To list."

Are customdocumentproperties in that list?

Perhaps look up help for custom document properties?


Creates a new custom document property. You can only add a new document property to the custom DocumentProperties collection.

expression.Add(Name, LinkToContent, Type, Value, LinkSource) Note there is no Item, nor Key, nor Before, nor After

expression Required. The custom DocumentProperties object.

Name Required String. The name of the property.

LinkToContent Required Boolean. Specifies whether the property is linked to the contents of the container document. If this argument is True, the LinkSource argument is required; if it's False, the value argument is required.

Type Optional Variant. The data type of the property. Can be one of the following MsoDocProperties constants: msoPropertyTypeBoolean, msoPropertyTypeDate, msoPropertyTypeFloat, msoPropertyTypeNumber, or msoPropertyTypeString.

Value Optional Variant. The value of the property, if it's not linked to the contents of the container document. The value is converted to match the data type specified by the type argument, if it can't be converted, an error occurs. If LinkToContent is True, the Value argument is ignored and the new document property is assigned a default value until the linked property values are updated by the container application (usually when the document is saved).

LinkSource Optional Variant. Ignored if LinkToContent is False. The source of the linked property. The container application determines what types of source linking you can use.


You were looking at a Collection made from scratch. Not the same thing at all. So the answer to


Is there any way that I can use the 'Before' and 'After' arguments for the Add() method of the CustomDocumentProperties collection?
is.....no. There are no such arguments.

avi10000
01-21-2013, 09:17 AM
>> You were looking at a Collection made from scratch.

Well - since VBA is supposed to be object oriented, i.e., I was expecting that the CustomDocumentProperties object would inherit from the global VBA Collection object and thus inherit all its properties and functions

-- and make my life much easier.

I simply wanted to be able to order the doc properties in the CustomDocumentProperties collection.

Wasn't that reasonable?

-avraham




"object Required. An object expression that evaluates to an object in the Applies To list."

Are customdocumentproperties in that list?

Perhaps look up help for custom document properties?



You were looking at a Collection made from scratch. Not the same thing at all. So the answer to


is.....no. There are no such arguments.

fumei
01-21-2013, 03:27 PM
I was expecting the CustomDocumentProperties object would inherit from the global VBA Collection object and thus inherit all its properties and functions.

Well...there is a BuiltinDocumentProperties collection and it does not have Add, or any other so-called global collection property/method.

The point being is "Collection" is not an global object per se. There is no inheritence.

There is inheritence among items IN a collection - all the items in the BuiltinDocumentProperties have the same properties and methods. But "Collection" itself is not an object.

"Wasn't that reasonable?" Sort of. Did you check the Applies to list that was mentioned? If something is not in there, then whatever you are looking at does not apply to that.

avi10000
01-24-2013, 02:57 PM
Thanks.

VBA drives me mad.

CustomDocumentProperties is a collection and IMO it should inherit from some Collection class.

VBA has so much richness but not quite enough. Either it is lacking a critical feature or some existing critical feature does not work.

Thanks.

-avraham




Well...there is a BuiltinDocumentProperties collection and it does not have Add, or any other so-called global collection property/method.

The point being is "Collection" is not an global object per se. There is no inheritence.

There is inheritence among items IN a collection - all the items in the BuiltinDocumentProperties have the same properties and methods. But "Collection" itself is not an object.

"Wasn't that reasonable?" Sort of. Did you check the Applies to list that was mentioned? If something is not in there, then whatever you are looking at does not apply to that.

fumei
01-24-2013, 05:50 PM
Chuckle. LOL

I have to agree. You are not the first to be driven mad by VBA. Sorry to have to be the one to deliver bad news.

The idea of VBA being an object-oriented language has been much discussed. The bottom line is that it is not a "true" OOP language, in that it does not have full polymorphism and inheritance. Yes you can make and use Classes, but again there is not "true" polymorphism and inheritance.


Bummer.

Still, it is what it is, and yes it DOES have some richness. Things would be much worse if it did not exist. But it ain't magic.

Frosty
01-25-2013, 12:34 PM
If you find something lacking in the VBA object model, you can often program it yourself (I've developed custom style classes, custom sentence classes, custom story range collections, etc etc) to provide the functionality you want.

But it has to be worth it. Why would the index of a customdocprop matter, though? Also-- have you checked that the index doesn't change, depending on whether the document has just had the customdocprop added vs. the document has been saved and re-opened.

Theoretical stuff aside-- all languages have their quirks and limitations-- it's just a matter of what is the most effective way to solve particular problems in a particular language. Sometimes it's a round-peg-square-hole problem, but other times you're just a hammer looking for a nail, rather than observing that you need to deal with the screw in front of you ;)

fumei
01-25-2013, 05:40 PM
"But it has to be worth it. "

Oh yeah....