From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Programmatically modify CustomDocumentProperties of a MS Word document using ActiveX or .Net

Solved!
Go to solution

Hi all,

I need to open an ms word document (that work for me as a template) then modify some custom document properties and finally save it with a different file name. Following MSDN information on ActiveX (or .Net) interface to word I succesffully opened and saved the document but I was not able to gain access to custom document properties. The problem seem to be caused by the type of the CustomDocumentProperties property of a Document object LabVIEW return.

As MSDN explay CustomDocumentProperies shoul be a collection of DocumentProperty. In a similar situation Documents is a collection of Document object returned as a property of the Application object. Documents is correctly returned as an object (with full access to all the methods and properties) on the other hand CustomDocumentProperty is returned as a variant (or, using .net, is returned as a generic SystemObject). I have tried to cast/convert this variant to the expected object but without succes (the variant seem to be a pointer, a 32 bit memory address, but probably of a different memory space).

 

I'v used LabVIEW 2009, LabVIEW 2010, Word 2003, Word 2007 under Windows XP 32bit and Windows 7 64 bit (in different combination)...

 

Any Suggestion? Someone know to recover the CustomDocumentProperties object or a different way to modify a CustomDocumentProperty? 

 

My last option is to use VBA... may be programmatically create a macro in the ms word document and then run it... horrible! 🙂

 

OMG... I can't believe.... this (use VBA) is exactly the approach used in the ReportGenerationToolkit... omg... omg... I checked it just before hit the send post button... omg... 

0 Kudos
Message 1 of 7
(6,041 Views)

I saw the previous VI you had posted in another thread regarding this same topic.

 

CustomDocumentProperties returns what Microsoft calls a Collection. I don't know what is LabVIEW's equivalent of a Collection. Perhaps someone else can chime in on how to handle this type of object.

 

I tried using Variant to Flattened String on BultinDocumentProperties which is similar CustomDocumentProperties to see what it returned, since unlike e CustomDocumentProperties which is probably empty with a new document, BultinDocumentProperties should have some information. I came up empty.

 

 

0 Kudos
Message 2 of 7
(6,034 Views)

For people who are interested in querying for and modifying the CustomDocumentProperties and BuiltinDocumentProperties,

Microsoft offers the DsoFile.dll available from http://support.microsoft.com/kb/224351

 

It works perfectly for me with LabVIEW 8.6, Win XP, Word 2003 using ActiveX automation included in LabVIEW.

 

According to Microsoft you don't even need to have Office installed to modify those properties.

I couldn't test out that since my PC with LabVIEW also has Office installed.

 

 

 

Message 3 of 7
(6,021 Views)
Solution
Accepted by D4N!3L3

Here (http://forums.ni.com/t5/LabVIEW/Modify-word2003-CustomDocumentProperties/td-p/952237) I've found useful information that led me to the attached solution.

 

Thanks to all.

Message 4 of 7
(5,981 Views)

Using the DsoFile.dll that I mentioned in my post above would be best and quicker since it does not require opening and closing of Word files.

 

 

0 Kudos
Message 5 of 7
(5,974 Views)

True, and requiring that ms word is installed is quite bothersome, but what about the process of fields updating?

In my template .doc these custom properties are present in the header, footer and in the "main story" region and I need that these fileds are updated, according to the associated properties. A (deep) document modification is required and I don't think that dsofile.dll is able to do so (I've read the kb and I've not found any mention on fields updating). That's reason I've used the ActiveX+VBA.

0 Kudos
Message 6 of 7
(5,969 Views)

@Danele wrote:

True, and requiring that ms word is installed is quite bothersome, but what about the process of fields updating?

In my template .doc these custom properties are present in the header, footer and in the "main story" region and I need that these fileds are updated, according to the associated properties. A (deep) document modification is required and I don't think that dsofile.dll is able to do so (I've read the kb and I've not found any mention on fields updating). That's reason I've used the ActiveX+VBA.


The DsoFile.dll is specifically for Document Summary properties. Those that you can see if you right-click on a file. Since the title of your initial post was about CustomDocumentProperties there is no need to lead them to the your other post.

 

 

 

 

0 Kudos
Message 7 of 7
(5,964 Views)