Macro to Set Checkbox Based on Value of SharePoint Document Property RRS feed

  • Question

  • I'm a total beginner for writing a Word macro, or anything in VBA for that matter. But I figure that what I want to do can't be too hard. I have request forms (Word documents - .dotm files) stored in a SharePoint 2010 site. I've configured the SharePoint content type with three columns - each is a choice field with Yes or No as the values. Perhaps I could use true/false when I know something more about macros. My client would like those Yes/No fields to be shown in the document as checkboxes - it looks better! So I think what I need to do is have a macro that runs whenever the document is opened to check the value of the SharePoint columns - ActiveDocument.ContentTypeProperties("column name").Value - and set the ActiveDocument.FormFields("checkbox name").Value to true or false accordingly, using an If Then Else statement. Similarly I'll need to do the reverse whenever a document is saved (check the FormFields and set the ContentTypeProperties).

    So where to start? Developer tab, Macros, Create...but then what?



    SharePoint Systems Officer, Capital Regional District, BC, Canada

    Monday, July 29, 2013 10:40 PM

All replies

  • Hi,

    I think what you want is that how to create a Word macro.

    So the following link will help you:


    Jaynet Zhang
    TechNet Community Support

    • Marked as answer by Jaynet Zhang Wednesday, July 31, 2013 1:40 AM
    • Unmarked as answer by Tom Benjamin Wednesday, July 31, 2013 2:03 PM
    Tuesday, July 30, 2013 3:10 AM
  • That's link is useful, but hardly an answer!

    How do you write a Word macro that runs automatically whenever a document is saved and opened?

    How do you get the macro to access the values in form controls (checkboxes) in the document? What is the syntax for checking whether the box is checked or not?

    How do you get the macro to update the SharePoint properties of the document?

    How do make sure this macro is executed in all documens based on the template file?


    SharePoint Systems Officer, Capital Regional District, BC, Canada

    Wednesday, July 31, 2013 2:03 PM
  • Hi,

    Once you have added a Yes/No field to the SharePoint content type, you can insert the filed by navigating in the following manner :

    Insert -> QuickParts -> Document Property -> Yes/No

    This inserts Yes/No property as a dropdown list to the document and it can be toggled from the word document and automatically updates the document library field on save.



    Saturday, August 17, 2013 1:34 AM
  • Thanks Pradip, but I know that. My question is how do I get a checkbox in the Word document - not a Yes/No choice connected to a SharePoint property, that is simple to do.


    SharePoint Systems Officer, Capital Regional District, BC, Canada

    Saturday, August 17, 2013 1:56 AM
  • Hi Tom,

    If you are going to use a macro driven template (dotm) you can insert "Auto" event macros, which will run when the event is triggered. Here is a link that explains it. http://word.mvps.org/faqs/macrosvba/documentevents.htm

    Regarding checking or marking the value of embedded check boxes, here is sample code that finds a certain check box.

    Sub FindFormControls()
        Dim doc As Word.Document, fld As Word.FormField
        Set doc = ActiveDocument
        For Each fld In doc.FormFields
            If fld.Type = wdFieldFormCheckBox Then
                If fld.Name = "Check1" Then
                    If fld.CheckBox.Value = True Then MsgBox "It's Checked"
                End If
            End If
    End Sub\
    Hope this helps

    Kind Regards, Rich ... http://greatcirclelearning.com

    Saturday, August 17, 2013 1:20 PM
  • I'm posting a link to an entry Marat Bakirov made on msdn blogs. His solution doesn't require macros and is simple to implement (once you read and understand it).  It may take about ten minutes to comprehend it the first time, thereafter, this can be done in less than a minute.


    Since I'm not a regular user, I'm prevented from submitting hyperlinks.  As such, I took out the https:// at the beginning of the address above to keep the auto format from turning the text into a hyperlink.

    Tuesday, May 10, 2016 3:00 PM