Customdocumentproperty on Readonly document

P

Peter Karlström

Hi

I have a COM-Addin for Word 2003 which involves the use of a number of
customdocumentproperties.
When a document is opened I read these properities in order to make
some decisions.
But when a document file is readonly (R file attribute set) I'm not alowed
to read them. I get the error 5941 (member is not part of the collection).
But from Windows Explorer I can see the properties of the file and all
the customdocumentproperties are visible and readable. Why not from Word
itself?

Is there a way around this or is "by design"?

Thanks in advance
 
P

Peter Karlström

Hi Jialiang Ge

Thank you for your reply.
It seems that the looping-approach is important.
As in your sample, I created a For Each oProp in <object>.CustomProperties
and succeeded in getting the values even when the dokument file was readonly.
My old approach below does not work (hope this is readable).
(ActiveDoc) is set in wrdApp_WindowActivate and is dokument.Name

+++ Start Code +++
tstVal =
Trim(wrdApp.Windows(ActiveDoc).Document.CustomDocumentProperties("int_doctype"))
If Err.Number <> 0 Then 'Non-Documentum-document
CheckDocOrigin = WrdDefault
Else
tstVal =
Trim(wrdApp.Windows(ActiveDoc).Document.CustomDocumentProperties("su_status"))
If Err.Number <> 0 Then 'Old documentum-document
CheckDocOrigin = DocumentumOld
Else 'New documentum-document
CheckDocOrigin = DocumentumNew
End If
End If
+++ End Code +++

I wonder why my first approach doesn't work. It works fine for non-readonly
documents.

Regards
--
Peter Karlström
Midrange AB
Sweden
 
J

Jialiang Ge [MSFT]

Hello Peter,

I tried to get the custom document property without looping throught the
collection, and the property value is still successfully outputted on my
side.

My test is based on the source code and word document I sent you in my last
reply. I add the code

MsgBox(oCustomProps("Editor").Value)

immediate after the line
oCustomProps = oDoc.CustomDocumentProperties

because I know there is a customer property "Editor" in my test document.

Would you try it on your side and let me know if it works?

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
P

Peter Karlström

Hi Jialiang Ge

I have tried the code you sent in a VB6 project.
I get an Error 91 (Object variable or With block variable not set) on the row
oCustomProps = oDoc.CustomDocumentProperties

This is the complete test-code:
Private Sub Command1_Click()

Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oBuiltInProps As Object
Dim oCustomProps As Object
Dim oProp As Object
Dim index As Integer

'Create an instance of Word and make it visible.
Set oWord = CreateObject("Word.Application")
oWord.Visible = False
Set oDoc = oWord.Documents.Open("C:\TEMP\TestProperty.doc", True, True)

'Get the Custom Document Properties collection.
oCustomProps = oDoc.CustomDocumentProperties
For index = 1 To oCustomProps.Count
oProp = oCustomProps.Item(index)
MsgBox (oProp.Name & " " & oProp.Type & " " & oProp.Value)
Next

'Clean up. We'll leave Word running.
oWord.Quit
oCustomProps = Nothing
oBuiltInProps = Nothing
Set oDoc = Nothing
Set oWord = Nothing
End Sub

What seems to be wrong?

Regards
 
J

Jialiang Ge [MSFT]

Hello Peter,

The code in my last reply is written in VB.NET. Sorry for not clarifying
it. In the syntax of VB6, all the object assignment should start with the
keyword 'Set', otherwise, we will get the error 91 (Object variable or With
block variable not set). Therefore, the VB6 code of my sample should be:

Private Sub Command1_Click()
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oBuiltInProps As Object
Dim oCustomProps As Object
Dim oProp As Object
Dim index As Integer

'Create an instance of Word and make it visible.
Set oWord = CreateObject("Word.Application")
oWord.Visible = False
Set oDoc = oWord.Documents.Open("D:\TestProperty.doc", True, True)

'Get the Custom Document Properties collection.
Set oCustomProps = oDoc.CustomDocumentProperties
For index = 1 To oCustomProps.Count
Set oProp = oCustomProps.Item(index)
MsgBox (oProp.Name & " " & oProp.Type & " " & oProp.Value)
Next

'Clean up. We'll leave Word running.
oWord.Quit
Set oCustomProps = Nothing
Set oBuiltInProps = Nothing
Set oDoc = Nothing
Set oWord = Nothing
End Sub

Please try it again, and let me know if it works for you.

Thanks
Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
P

Peter Karlström

Hi Jialiang Ge

You are so right. I had forgot two other props where I should use Set,
Set oCustomProps and Set oProp

Now it's working fine.

Thanks a lot.

regards
 

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