(Custom) Document Properties

Add-in Express™ Support Service
That's what is more important than anything else

(Custom) Document Properties
 
Kevin van Zanten




Posts: 22
Joined: 2010-03-12
I'm trying to read default property information from the document (Word 2007), and also trying to store (and read) custom properties, but I haven't gotten it to work using examples from other threads. I'd like to start anew but frankly I have no idea wh ere to start.

An overview of things I want to do;

1) Read default document properties;
2) Store custom document properties;
3) Read custom document properties.

Thanks in advance,
Kevin
Posted 26 May, 2010 08:41:12 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Kevin,

Note that all object models in Office are not thread-safe. That is, using any Word objects in a thread isn't recommended.
.NET, Extended MAPI, Windows Phone & RT
Posted 26 May, 2010 09:04:16 Top
Kevin van Zanten




Posts: 22
Joined: 2010-03-12
You'll have to forgive me, I'm rather new to all this. Would you be able to give me a hand or point me in the right direction, where I can find out how to go about this? It probably isn't difficult, but I have no idea where to start or what to access.
Posted 26 May, 2010 09:08:43 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Kevin,

Sure.

Getting help on COM objects, properties and methods
To get assistance with host applications’ objects, their properties, and methods as well as help info, use the Object Browser. Go to the VBA environment (in the host application, choose menu Tools | Macro | Visual Basic Editor or just press {Alt+F11}), press {F2}, select the host application in the topmost combo and/or specify a search string in the search combo. Select a class/property/method and press {F1} to get the help topic that relates to the object.
.NET, Extended MAPI, Windows Phone & RT
Posted 26 May, 2010 11:38:09 Top
Heinz-Josef Bomanns




Posts: 201
Joined: 2008-02-28
Kevin van Zanten writes:
1) Read default document properties; 2) Store custom document properties; 3) Read custom document properties.

Best practice, besides F2/Object browser, to learn such things is t use the macro recoder built in the office applications. Unfortunatly 2007 is not very helpfull with this due to the new UI. If available use an older version like 2003, 2002, 2000. Start macro recording, set or alter some builtin or user defined/custom document properties, stop macro recording and have a look at the resulting macros in the VBA IDE...

Here's some simple code adding/refreshing a custom property and altering a builtin property, maybe it helps:


  On Error Resume Next
  With gobjWord.ActiveDocument
    X$ = "Some text to store..."
    Err = 0 'Try to add a new variable
    .Variables.Add "VarName", X$
    If Err <> 0 Then 'Variable exists, just change value
      .Variables("VarName").Value = X$
    End If
    .BuiltInDocumentProperties(wdPropertySubject) = "Some text to store..."
  End With


Don't forget to '.Save' the altered document somewhere...
__________________
Greetings, HJB
Posted 26 May, 2010 20:34:37 Top
Heinz-Josef Bomanns




Posts: 201
Joined: 2008-02-28
Just found this one in another thread, maybe it's helpfull:

http://msdn.microsoft.com/en-us/library/4e0tda25%28VS.80%29.aspx
__________________
Greetings, HJB
Posted 26 May, 2010 20:45:17 Top
Kevin van Zanten




Posts: 22
Joined: 2010-03-12
Gentlemen, thank you both for your assistance. I should have mentioned that the language I'm using is C# (Visual Studio 2008).
Also I thank you for the link, but that's one of the things I couldn't get to work.
I'll have a look through the object browser and see if I can get it working with that information.
Posted 27 May, 2010 01:41:54 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Kevin,

Feel free to contact us if I can help any further.
.NET, Extended MAPI, Windows Phone & RT
Posted 27 May, 2010 03:34:16 Top
Kevin van Zanten




Posts: 22
Joined: 2010-03-12
Dear Mr Astafiev,

I managed to get it to work, thank you for your help.
Posted 27 May, 2010 03:35:58 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Good news!

Thank you for letting me know, Kevin.
.NET, Extended MAPI, Windows Phone & RT
Posted 27 May, 2010 04:30:19 Top