Results 1 to 3 of 3
2009-04-20, 23:38 #1
- Join Date
- Apr 2009
- Thanked 0 Times in 0 Posts
I need a VBA script or some ideas on how I can add a unique ID (UID) into a MS Word 2003 document.
The unique ID would consist of a 4 char string prefix followed by an integer number. The 4 char prefix is set once for the document. The integer part would start at one and be incremented upwards each time a UID is added.
Example UID: RTED1, RTED56, RTED781 etc.
The general scenario of use is as follows.
The user places the cursor at a location within a paragraph where the UID needs to be inserted.
The user selects either a toolbar icon or a short-cut key which would launch a macro that checks to see what was the last integer number used, increment this and then insert the UID into the cursor position.
The only specific font settings would be that the colour of the UID is red and bold, everthing else such as font name, font size can be inherited from the paragraph style.
The prefix and last integer number used needs to be retained with the document so that subsequent UID's can continue to be added in later editing sessions. Using existing document property fields to store the prefix and last integer number used would be OK eg: Keywords, Comments; but if there are any hidden meta data fields that could be used that would be ideal.
Thanks in advance.
2009-04-21, 01:19 #2
- Join Date
- Feb 2001
- Silicon Valley, USA
- Thanked 93 Times in 89 Posts
[quote name='badga' post='771492' date='20-Apr-2009 20:38']The prefix and last integer number used needs to be retained with the document so that subsequent UID's can continue to be added in later editing sessions. Using existing document property fields to store the prefix and last integer number used would be OK eg: Keywords, Comments; but if there are any hidden meta data fields that could be used that would be ideal.[/quote]
In addition to the document properties visible in File > Properties, Word support document variables. These are internal to the file and not exposed to end users. Both document properties and document variables are vulnerable to erasure if the user check the option to clear private data from the document upon save. So you might want to add to your macro to check this option and turn it off.
2009-04-22, 22:58 #3
- Join Date
- Dec 2000
- New York, NY
- Thanked 29 Times in 27 Posts
You might also be able to do this without resorting to doc properties or doc variables, since the integer information would be stored in the UID text entries themselves. You could have the macro wrap every newly-inserted UID in a bookmark, whose unique name contains the same integer as is used in the UID text it wraps - so for example, you could have bookmarks named UID1, UID56, UID756 etc. When each new UID gets inserted, the macro could cycle through the bookmarks collection, and determine the highest number from the bookmark names, and increment accordingly.Gary Frieder