How to make a Word document force me to fill in some fields when I open it?
You can use the VBA event Document_Open to achieve this. You will need to save the document as a .docm
file for it to work (Word Macro-Enabled Document.)
Press Alt+F11, and add this code to the ThisDocument
object:
Sub Document_Open()
MsgBox "Don't forget to amend the fields!"
End Sub
You can do a lot more than just show a MsgBox of course.
To expand upon this and actually populate data from the prompt, you could use input boxes or a custom form. I'll go through input boxes here, as forms are a bit longer and more complicated.
First, we need to add form fields for the data we actually want to populate. I'll show you the most compatible way to do this.
You may need to enable the Developer
toolbar for this. Some instructions to cover different versions of Word are here, for mine, I had to enable it here:
Next, we'll add the form field:
Right click the new form field and click Properties
. Give the field a Bookmark
that clearly references it:
Now, in VBA, we can change this value using text from an input box:
Sub Document_Open()
ActiveDocument.FormFields("CompanyName").Result = InputBox("Enter your company name here")
End Sub
You can obviously add as many of these as desired.
Note: The grey background - field shading
- does not show up in print, but if you want to remove it you can click your field and click this button in the same place you added it from:
Related videos on Youtube
rodsarria
Updated on September 18, 2022Comments
-
rodsarria over 1 year
I have a Word document that I use for quotations. Every time I make new one, I need to change some fields (company name, person addressed, etc.). I want the file to require me to fill in those fields in a pop-up window when I open it, so I don't miss any. Is this possible?
-
fixer1234 about 8 years"Prompting you to fill in the fields" is ambiguous. Are you looking for simply a reminder message (as described in Jonno's answer), or a requirement to fill in the fields, which are prompted, before it will allow you to create the quote?
-
rodsarria about 8 yearsAs a requirement to fill in the fields. Thanks for the suggestion, I will edit my question.
-
-
rodsarria about 8 yearsNice one. But what if I need to fill in the fields from the pop-up window? Is this possible?
-
Jonno about 8 years@rodsarria Yes absolutely. I've added an example of this.
-
rodsarria about 8 yearsI got a problem. Now, every time I open a Word document, it shows the pop-up window. Can I restrict this only for my quotation document?
-
Jonno about 8 years@rodsarria sounds like you added the event handler to 'Normal' instead of your actual document.