Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Wrriting Word add-in’s “meta-data”/”user-data” within a Word document?

Posted on 2014-10-09
5
Medium Priority
?
439 Views
Last Modified: 2014-10-10
I’m developing a Word add-in, and I need to be able to write some kind of add-in’s “meta-data” or ”user-data” within the Word document. This data should be present inside the document, readable and editable by add-in (i.e. VBA), and of course, not directly visible by end user… How this can be done?
0
Comment
Question by:npaun
  • 2
  • 2
5 Comments
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40370459
I don't think you can really do that.

You can certainly hide it as custom metadata, which I think most software programmers do, but I think the end user always has the choice of seeing it. See the article about "Viewing Microsoft Word document properties from the File Menu" for more information.

If you are worried about the end user editing it, then you could always add a checksum and test whether it has been altered.

If the question is: how do you access Word's document properties from VBA?, then there is an article on how to do that there to.
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 40371069
You can store text as one or more document variables. They are like custom properties, but are not directly visible in the user interface.
Here is some sample VBA code
    Dim var As Variable
    
    Set var = ActiveDocument.Variables.Add("MyVar", "Some text")
    var.value = "some new text"
    MsgBox ActiveDocument.Variables("MyVar").value

Open in new window

0
 

Author Comment

by:npaun
ID: 40371831
Than you for the posts

@GrahamSkan
This is pretty much what need. At first, I thought that it would not be the solution, as I didn't expect that the content of the Variables is saved in file when document is closed and that it will be lost as soon as Word doc is closed, but test demanded me, and the Variables content is saved with the document, just as I need...

One more thing: is there a way to clear the Variables property, and tho remove its members one by one? Since, as far as I can see, it doesn't have a Remove method, so I don't see how to remove elements of this "collection"?
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 40371948
There are no special methods to handle the Variables collection. Try this to clear all document variables:
    Do While ActiveDocument.Variables.Count > 0
        ActiveDocument.Variables(1).Delete
    Loop

Open in new window

0
 

Author Comment

by:npaun
ID: 40372786
@GrahamSkan
Problem solved!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
With its various features, Office 365 can not only help you with your day-to-day business tasks, it can also do wonders for your marketing campaign.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question