Word Template – Empty/Refresh Field Value in Document Property

0
173

Introduction

We will see how to show nothing on Word document while document property field is empty. Also, we will write one macro to update fields whenever document gets open. I am going to use Sharepoint library so document properties will be my Sharepoint library columns.

Let’s See How to Write Condition in Word Document

Note: You can use a simple Word document to write if condition within it. But here in the example, I am going to show macro. So I am using below macro enabled word document type.
  1. Create one Word document file which has type “Word Macro-Enabled Document“, which has (.docm) extension. It is basically Word file with macro enabled functionality.

    • Upload it into your Sharepoint library (which will work as template library).

    • Word document allows us to write condition within it.

      Quote:


      1. Ctrl + F9 : Creates curly braces which allow us to add condition.
      2. Alt + F9 : Show/Hide all conditions on document.

    • Press ctrl + F9, it will create curly braces in Word document. Write if condition within curly braces. See the below image.

    • Press Alt +F9 to hide all conditions in Word document. Upload it back to Sharepoint library -> Fill out the associated library columns and check its value will be available in the document.

Let’s See Macro Method to Update Fields Whenever Document Gets Open

In my previous blog, user will phase one problem. Whenever fields value gets changed, it will not automatically refresh in document. So we are going to use macro to refresh all fields on document.

Quote:


Previous blog url : 
https://www.codeproject.com/Articles/1198352/Use-word-document-as-template-in-sharepoint

  1. Create macro in document.

  2. Edit it into “Microsoft Visual Basic” and write the below method for refresh all the field’s value.

  3. Save it and upload it back to Sharepoint library. So whenever any document is generated through macro enabled template file, the document itself updates all fields when it gets open.

Test the Above Macro Enabled Word Document

  • As per the previous blog, you should upload macro enabled document in template library.
  • You should also update template url in contenttype. Go to content type “Customer_Content_Type” -> Advance settings -> Update template URL (now it is having .docm extension)

LEAVE A REPLY