DSO and Custom Properties

G

Guest

I assign a custom property to a file (a.xls); the property name is "Balance"
and its value is 123.45

In another file the following code does retrieve the 123.45:

Sub surface()
Dim FileName As String
Dim DSO As DSOFile.OleDocumentProperties
Set DSO = New DSOFile.OleDocumentProperties
FileName = "C:\a.xls"
DSO.Open sfilename:=FileName
MsgBox (DSO.CustomProperties.Count)
MsgBox (DSO.CustomProperties.Item("Balance").Value)
DSO.Close
End Sub

I would like to get the value without knowing the name; both:
MsgBox (DSO.CustomProperties.Item(1).Value)
and
MsgBox (DSO.CustomProperties.Item(1).Name)

fail. How can i get the name of the first custom property??
 
C

Chip Pearson

The following works fine for me using DSO 2.0.


Dim DSO As DSOFile.OleDocumentProperties
Dim CustProps As DSOFile.CustomProperties

Set DSO = New DSOFile.OleDocumentProperties

DSO.Open "Book5.xls", True, dsoOptionDefault
Set CustProps = DSO.CustomProperties
Debug.Print CustProps(1).Name, CustProps(1).Value
DSO.Close


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting LLC
www.cpearson.com
(email on the web site)
 
G

Guest

Thank you Chip.

To get it to work I had to add a second custom property, however.
I wondow why?
 
G

Guest

Gary''s Student said:
Thank you Chip.

To get it to work I had to add a second custom property, however.
I wondow why?


Looks like you need to use a zero based index

Dim DSO As DSOFile.OleDocumentProperties
Dim CustProps As DSOFile.CustomProperties

Set DSO = New DSOFile.OleDocumentProperties

DSO.Open "Book1.xls", True, dsoOptionDefault
Set CustProps = DSO.CustomProperties

If CustProps.Count = 1 Then
Debug.Print CustProps(0).Name, CustProps(0).Value
End If

DSO.Close
 

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