Solved

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

Posted on 2014-10-09
5
406 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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Suggested Solutions

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
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  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

738 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