Solved

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

Posted on 2014-10-09
5
413 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month7 days, 1 hour left to enroll

622 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