1

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:

  1. Open the reference document
  2. 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).
  3. Save the embedded document as a .doc with the inputs inserted
  4. 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

4
  • It is not clear for me. You have an Excel spreadsheet. Within you have an embedded document - Excel or Word or anything else? Which of them is the "report"? Do users fill in data in the main spreadsheet ant later it automatically updates in the embedded document, or vice versa?
    – ZygD
    Feb 14, 2015 at 8:15
  • Thanks for the response! I have an Excel spreadsheet with an embedded Word document. The embedded document is a template for a report. Initially, the user inputs values into the spreadsheet, calculations are done via excel, and the resulting outputs get inserted into the embedded word document, replacing text form fields. The macro finishes by saving their completed report as a .doc and reverting the sheet back to a template. The goal is to allow the user to edit the template via excel, to fit their needs, but I worry they might erase a text form field while doing this. Is that clear?
    – Sooji
    Feb 15, 2015 at 2:26
  • Thanks. Now it is clear. I was able to replicate your situation. But so far I would not have a cure for your problem. Actually, I can see your problem - I do have hard time in writing info in those text form fields, as I always keep deleting them! I think, if it is possible, maybe creating some kind of a new event to capture field deleting would help you? To bad I have poor experience in creating events, but in this case I do not see another way except employing events in one or another way.
    – ZygD
    Feb 17, 2015 at 6:48
  • Thanks for the giving it a shot, ZygD! I came up with a work around for now. I tried a protecting the sheet but then allowing editing in all sections but the form fields. It worked for the most part, but I ran into a whole slew of new protection checks that made it very convoluted. Ultimately I just implemented a Bookmarks.Exists logic to allow users to erase parts if they wanted to and added a "reset template" button if they happened to erase a text form field they didn't mean to, reverting all changes. It's not perfect/elegant, but it's cleaner than everything else I was trying.
    – Sooji
    Feb 18, 2015 at 13:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.