VBA: Custom document properties, best practices/limitations? (Word 2016)

Anonymous
2017-10-18T18:49:39+00:00

Word 2016 (x32) on Win7 (x64)

I have a project with scope creep; a single-use document (open document, a userform to make changes, convert to PDF) needs to be converted to allow the document to be passed around and opened/edited multiple times before being completed. I need to create an audit trail, to capture what changes are made through the UI/userform (which consists of some radio button selections, some combobox selections, and some text box [free entry] fields).

One approach to persist the data (other than a bunch of hidden bookmarks?) would be to create a list of about 200 custom document properties, with null values in the template. Then for each item the userform controls, I can capture the audit trail info (what value was selected, by whom, and on what date). I can also use this data to 'block' someone from changing a selection after a prior selection has made an irrevocable change to the document.

I know I can (technologically) use VBA to:

* create the CDPs - too many to type in manually

* clear the CDPs, to reset the template during testing

* update the CDPs with the relevant values once the template is in use.

My current understanding is that the String CDPs have a ~255 char limit, other than that are there any other gotchas or limits that I should consider in advance of implementing this approach? I can limit my UI so that the actual content (plus my audit info) never exceeds 255 chars.

Each row below represents one CDP. CDP values that can be overwritten/updated do not require an audit trail beyond the most recent value/selection.

(ignore the spaces, I can use a control character to separate the values to compress the strings).

CDP Name         lastUpdated              LanID              Value                    AllowUpdates

cmb18                2017.10.18              ABCD999        ArtificialFlavor          False

rdo12                   NULL                      NULL               NULL                     NULL

cmb07                2017.10.04             DEFG888          RedDye#5               True

Thanks in advance for any advice or warnings that will keep me from going down the wrong path!

[ Moved from: Office / Word / Microsoft Office Programming / Office 2007 ]

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Anonymous
    2017-10-18T22:10:09+00:00
    1. Consider either document variables (also stored in the document, but not user-modifiable using anything in the default UI), or saving your data in a Custom XML Part. Document Variables are easier to use than Document Properties and there are fewer restrictions. (e.g., I thought there was a restriction on the number of CDPs, but you certainly create hundreds of thousands of Document Variables -I never found the limit. You may be able to store more data per variable as well.
    2. If you really want to make sure the saved data is not tampered with, consider using the Windows CryptoAPIs. Long time since I did that though!
    2 people found this answer helpful.
    0 comments No comments
Answer accepted by question author
  1. Charles Kenyon 158.8K Reputation points Volunteer Moderator
    2017-10-19T21:21:04+00:00

    Agreeing with the recommendation to use document variables rather than properties:

    See Jonathan West's response inthis thread.

    The number of characters allowed in a document variable is 64K.

    0 comments No comments
Answer accepted by question author
  1. Anonymous
    2017-10-18T22:53:27+00:00

    I agree with Peter, you should use Document Variables for this solution. I would also add that if this is "really" important than you use a VSTO add-in solution versus a Document Level VBA solution.

    The VSTO add-in deployed on all systems that have access to the document can better ensure integrity of the audit data.

    0 comments No comments

0 additional answers

Sort by: Most helpful