Results 1 to 20 of 28

Thread: Macro Help

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    VBAX Regular
    Joined
    May 2024
    Posts
    15
    Location
    Sub CheckBoxesByTag()
        Dim propertyNames As Variant
        Dim propertyValue As Variant
        Dim cb As ContentControl
        Dim tagToFind As Variant
        Dim propertyName As Variant
        ' Define the names of the custom properties to check
        propertyNames = Array("DCR Type", "Classification")
        ' Loop through each property name in the array
        For Each propertyName In propertyNames
            ' Get the value of the custom property
            'On Error Resume Next
            propertyValue = ActiveDocument.CustomDocumentProperties(propertyName).Value 
            'On Error GoTo 0
            ' Define the tag to find
            tagToFind = Array("Addition", "Deviation", "Change", "Removal", "Class A", "Class B", "Class C", "Class D")
            ' Make sure to enclose string values in double quotes
            ' Check if the custom property exists and has a specific value 
            If Not IsEmpty(propertyValue) And propertyValue = tagToFind Then 
                ' Loop through content controls to find checkboxes with the specified tag
                For Each cb In ActiveDocument.ContentControls 
                    If cb.Type = wdContentControlCheckBox And cb.tag = tagToFind Then 
                        ' Unlock the content control
                        cb.LockContentControl = False
                        ' Allow editing of the content control 
                        cb.LockContents = False 
                        ' Check the checkbox 
                        cb.Checked = True 
                        ' Lock the content control 
                        cb.LockContents = True
                    End If 
                Next cb
            End If 
        Next propertyName
    End Sub


    error 13 type mismatch
    Last edited by Aussiebear; 05-07-2024 at 03:32 PM. Reason: Tidy up code presentation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •