Locking text fields in embedded document - vba

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

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.

vb.net word automation - bookmarks

I am preparing to make mechanism to fill out word template. I want to fill out it by data from my program. I heard about word bookmarks that I could create and then from program put the data to it. Unfortunately I heard also that when I want to put same value in different places in word I need to prepare separated new bookmarks for it. For instance I want surname to be in 3 different places in word then i cannot use one bookmark for it. Is it true? If so is there any other way to do it?
Yes, you can fill out bookmarks from your program. Be aware of the two different types of bookmarks which are called open or closed (one is empty, the other contains text and you can replace parts of the text or the whole text).
Yes, you can use a bookmark name only once. But you can manipulate the bookmarks in your program when you use bookmarks like bookmark_1 and bookmark_2, so you can replace the same content on different places. Helpful is the object model (https://msdn.microsoft.com/en-us/library/ff841749%28v=office.14%29.aspx)

VBA code in a template

In a Word template I have a command button with VBA code behind it.
The problem is that the code gets lost when a document is created using that template. The button is still visible, but the VBA code behind it disappears for some reason. This causes the button just to be clickable without performing any action.
The documents are saved in .docx format.
How can I 'glue' the button to its code so it doesn't get lost ?
First, make sure your VBA code is saved in the .dotm template that you make available to everyone (and not in your personal normal.dot/dotm template — this is only available on your machine).
Then, make sure the documents generated from the template are saved as .docm (not .docx).
.docx documents cannot contain VBA code. Anything saved in .dotx or .docx format will, by definition, lose all VBA code.
In a comment you say
"this doenst matter, as the document is just used for the macro."
This is incorrect; it does very much matter. .docx documents can't "be used for" macros because they can't contain macros.
For the macro to be always available, you need to store the macro in the normal template.
For example when recording a macro, select All Documents (Normal.dot) on Store Macro in.

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.

Transferring Rich Text data from Access to Word

I've been saddled with supporting an old Access 2003 database (with SQL backend) produced by a now out-of-business contractor.
The database includes several 'unconventional' reports. They all use Automation through VBA to output fields directly to a Word document. Kind of like this (pseudo code):
for each row{
output(row.id);
moveRight();
output(row.firstName);
newLine();
}
Etc.
The problem is, the database includes several rich text fields. To output these (including their formatting) to the document, the developer opens a separate Access form, with a single rich text control, and pulls the appropriate field into the text box.
He then does a 'select all, copy', flicks back to Word, and then pastes the text.
My task is to add a new rich text field to a report, and I feel there must be a better way of doing this...
Ah! A duplicate question apparently.
Here's the answer:
Word Automation: Write RTF text without going through clipboard