Built-in properties

G

GB

Hi, I've just found out there is a built-in properties thingy, and I found
out that there seem to be 30 of them. However, I had to write some code to
list them out (below, in case you need it) and I still don't have
definitions of what these properties actually are. It's fairly obvious what
most of them are, but what is 'format' for example?

The inbuilt help never seems to just give a simple listing of these
different options. Why would that be?

Here's the code to list them, btw:

Sub GetBuiltInDocumentProperties()
On Error Resume Next
mytext = ""
For i = 1 To 255
mytext = mytext & i & " " &
ActiveDocument.BuiltInDocumentProperties(i).Name & ":- " &
ActiveDocument.BuiltInDocumentProperties(i).Value & vbCrLf
Next
MsgBox mytext
End Sub

This lists out properties 1 - 30, but how do I know there isn't a property
number 699 (or 6,000,699) for example?
 
K

Klaus Linke

Use "For Each", and it doesn't matter how many there are :)

Dim myText As String
Dim myProp As DocumentProperty
On Error Resume Next
myText = ""
For Each myProp In ActiveDocument.BuiltInDocumentProperties
myText = myText _
& myProp.Name & ":- " _
& myProp.Value & vbCrLf
Next
MsgBox myText

Probably there isn't a standard on what you're supposed to use them for (say
"Format").

Regards,
Klaus
 
H

Helmut Weber

Hi GB,

Sub GetBuiltInDocumentPropertiesX()
Dim pDcm As DocumentProperty
Dim lNum As Long
' for ease of testing
ActiveDocument.Range.Delete
For Each pDcm In ActiveDocument.BuiltInDocumentProperties
lNum = lNum + 1
Selection.TypeText Format(lNum, "000 ") _
& pDcm.Name & vbCrLf
Selection.TypeText Format(lNum, "000 ") _
& ActiveDocument.BuiltInDocumentProperties(lNum).Name & vbCrLf
Next
End Sub
but what is 'format' for example?

Good question.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
H

Helmut Weber

Hi Klaus,

I'm intending to claim for:

"Reserved for future use"

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
K

Klaus Linke

|| Built-in document property "Format"

Helmut Weber said:
I'm intending to claim for:

"Reserved for future use"


If I had to guess: Somebody thought it a good idea to save the specific file
format (for Word say RTF 5, or DOCX 12...), so you could access it easily.
But somebody in the Word/Office team forgot to actually implement it (...
fill in sensible info).

Klaus
 
G

GB

Klaus Linke said:
Use "For Each", and it doesn't matter how many there are :)

Ah thanks. They hadn't invented 'For Each' when I learnt my programming,
which was really a long, long time ago.

I take it that you need to tell VBA what myProp is, so you include
Dim myProp As DocumentProperty

Does VBA infer the object type that you mean if there is only one type of
object in a particular collection? I guess that would be kind of risky
programming.

Then you can just use it naturally, as in
For Each myProp In ActiveDocument.BuiltInDocumentProperties or
myProp.Name

Nice!
 
K

Klaus Linke

You don't *have* to declare (Dim) your variables in VB(A).
The interpreter will figure out what kind of variable or object it is from
context if necessary, or even convert from one variable type to another
implicitly if necessary.

*BUT*... it's good practice to use DIM anyway. For one, you'll get error
messages immediately if you mistype, or use a variable/object incorrectly.
For another, IntelliSense can tell you which methods or properties are
applicable, so you can save a lot of typing (AutoComplete), and don't need
Help as much.

If you put an "Option Explicit" at the top of your code module, or if you
check the corresponding option in "Tools Options > Editor", the VBA editor
will remind you automatically if you forget.
I've checked everything on that dialog tab by the way... Not sure what the
default is, but I can use all the help I can get :)

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