Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-10-09
5
Medium Priority
?
431 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 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

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

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.
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

715 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