Solved

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

Posted on 2014-10-09
5
382 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
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
@GrahamSkan
Problem solved!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

772 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now