Where best to store a version number in Word document? - vsto

I have a VSTO Add-In that fills a specific Word template document with data from a third party software. The trick here is that some changes in the script are connected to changes in the document. What I want to do now is to manually store some kind of version number in the document information so I can check in the script if the version of the document fits the version of the script.
I already took a look here but there are too many possibilities and I don't just want to pick any random object. I need to store it somewhere where it doesn't get changed.
Where would you recommend to store such a value?
edit: the version number has to be set manually because not every change of the document affects the script.

You have three options:
Document property - can be displayed in a document by using a DocProperty field but can be viewed and easily changed by the user.
Document variable - an old school method but still valid. Can be displayed in a document by using a DocVariable field but can only be added, or the value changed, by using code.
Custom XML Part - can be displayed in a document by mapping to a content control which can allow the value to be changed by the user. If not mapped can only be changed using code, but not as simply as a document variable.

Related

How can I see the vb code of an UI made Publisher template

I'm using a publisher document as a template to create fitting instructions for our products. Everytime we launch a new product an individual instruction is produced which involves a lot of copy and pasting and then translating the master document into 4 different languages.
Although being individual to the product, there are only 5 sets of instructions with their own wordings (which doesn't change) and pics, the layout of the document is the same across all 5.
I was thinking to create a user form to enter the product name, choose the required set, insert photos and save the new doc as .pub and .pdf (only in English, I want to get this running first)
I tried around with Access and mail merge but it doesn't work the way I need it to. So I reverted to using VB in publisher where I've been basically able to return the text boxes, however, I can't see a way to display the code of the entire document with all text boxes and their formatting. Is this possible or would I have to code the entire document from scratch?
Thanks for reading and your input.

Locking text fields in embedded document

I have been tasked with updating a spreadsheet that produces a report by replacing text in a template. Previously, the worksheet referenced an outside/separate file-- my job is to get it working in an embedded document.
I currently have text form fields for every input I want to insert within the embedded document template. As it stands, users can edit the document template however they like, but if they accidentally erase a text form field (again, where text is replaced via the vba macro) then it will break the macro and the spreadsheet will be useless.
My question:
Is there some way to lock or protect text form fields such that the rest of the document is editable? I essentially want to have the inverse of a "text form field only" protection.
Alternatively, is there a better way to approach this project? I'm thinking of leaving the spreadsheet as is, but including a "reset" button bringing the template back to it's original state if anything breaks. If I did this method, this would require there NOT to be an external file. Attempts to do this so far have proven unsuccessful.
My general methodology/algorithm goes as follows:
Open the reference document
Replace all the text form fields via bookmarks with plain text,
making sure to reassign the bookmarks afterward (so as to not lose
them if they run the macro more than once).
Save the embedded document as a .doc with the inputs inserted
Replace all bookmarked inputs with text form fields to return the
template to its original state
Any information would be IMMENSELY appreciated. I am slowly running out of time and am feeling stuck.
Many thanks!
-Sooji

File attachment from HTML form doesn't get replaced on Domino server

I have a Domino database that stores documents with file attachments. The file attachments are stored in the Body RichTextItem as attachments.
For managing these documents I have an HTML form containing a file upload field.
Now, when I upload a file whose name differs from the current file in the document, everything works fine, and the uploaded attachment replaces the previous attachment.
The problem is when I upload a file that has the same name as the already existing file. In the WebQuerySave property of the form I call a LotusScript agent that should replace the old attachment with the one from the HTML form.
But in this agent I see two items called $FILE that have the same FileName. When I access them, I cannot distinguish these two items. I tried:
document.GetAttachment(filename) – obviously doesn't work, since the names are the same => I can only access the first attachment.
ForAll item in document.Items – I visit two items having the name $FILE, but both items are the same: the modification time is the same, the filesize is the same.
I could get all the attachments and remove all of them but the last. But is there any guarantee that the last item is the one from the HTML form? Or I could first extract the modification time from all the attachments and remember the newest. That must be the attachment from the HTML form.
Or is there a simpler solution?
For reasons like this behavior and several others, I have built most of the basic web facing Domino applications to store attachments on linked documents instead of the primary document. That way they can be accessed easily and do not get updated or modified except when they are supposed to be.

how to retrieve the name of an attached template via VBA when the template path has changed

I keep the template for the files I am working with in a dropbox and when I change to a computer with a different dropbox path, the template needs to be re-attached to the document. I would like to do this with a macro.
I can still see the name of the originally attached template in the "Templates and Add-Ins" Window, so the information must be somewhere stored within the document.
If however I try to retrieve the Name of the previously attached template via VBA by writing
strTemplate = ActiveDocument.AttachedTemplate
the result will be "Normal.dotm" and not "MyTemplate.dotm", which actually makes a lot of sense, but isn't what I am looking for.
Is there any way to retrieve the name and path of the previously attached template?
I think you can get the ful name (path+name) from
Application.Dialogs(wdDialogToolsTemplates).Template
and the name alone from
ActiveDocument.BuiltinProperties(wdPropertyTemplate)
The first time I tried the first of those, it didn't seem to work, but I could have been checking the wrong document. You won't find the Template property documented under the Dialog object - it's documented here
If those do not work, the only other ways I can see to do it would be
a. to look inside the .docx while it is closed (for a .docx), or maybe (I haven't checked) use dsofile.dll for a .doc, or
b. insert the field { template \p }, execute it and retrieve its result text
I found the answer here on stack overflow (unfortunately only after posting my question) as an answer to "How to open a word document without resolving the attached template?":
strOldTemplate = Dialogs(wdDialogDocumentStatistics).Template

Word 2010 - Force Formatting In Specific Parts of Document

I am working with Microsoft Word 2010. I have a document that serves as a template for multiple users for a project I am working on. There are two parts of the document I want to force formatting when a user types:
Enter in an email address - I want the address to not automatically turn to a hyperlink. I want it to not turn to a hyperlink on just this part of the document. The rest of it I want hyperlinks to be enabled.
Enter in a URL without www in front (i.e. google.com), and not have the first letter automatically capitalize. I don't want to turn off capitalizing the first letter of a sentence in the whole document. Just in this part of the document.
Is this something that can be done? I tried messing with Fields but did not have any luck. I am familiar with VBA so if there is a way to do this with code, I am open to that too.
Both features you requires are implemented in Word using AutoCorrect/AutoFormat. They are not controlled by the style mechanism and consequently can't be selectively activated.
The mail address formatting can be controlled by styles, and you could prevent the switch to the Hyperlink style from being visible. You could also consider a macro that selectively changes the styles of the text as required in a post-processing pass through the documents - perhaps the next time the document is opened by a user for review.