How to make a Word document force me to fill in some fields when I open it?

10,323

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.

enter image description here

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:

enter image description here

Next, we'll add the form field:

enter image description here

Right click the new form field and click Properties. Give the field a Bookmark that clearly references it:

enter image description here

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.

enter image description here

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:

enter image description here

Share:
10,323

Related videos on Youtube

rodsarria
Author by

rodsarria

Updated on September 18, 2022

Comments

  • rodsarria
    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
      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
      rodsarria about 8 years
      As a requirement to fill in the fields. Thanks for the suggestion, I will edit my question.
  • rodsarria
    rodsarria about 8 years
    Nice one. But what if I need to fill in the fields from the pop-up window? Is this possible?
  • Jonno
    Jonno about 8 years
    @rodsarria Yes absolutely. I've added an example of this.
  • rodsarria
    rodsarria about 8 years
    I 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
    Jonno about 8 years
    @rodsarria sounds like you added the event handler to 'Normal' instead of your actual document.