Word VBA to delete Content Controls with specific Tags

前端 未结 1 1946
执笔经年
执笔经年 2021-01-29 04:57

I read the answers to the question on How to find and disable a content control by tag on SO (below is the code for your convenience). In my case, I need to delete Content Contr

1条回答
  •  臣服心动
    2021-01-29 05:49

    Well, I was able to figure out ONE way of doing this....not the prettiest code and I'm sure there's a better way to do this. But, with my extremely limited VB knowledge, the below is working for my needs:

    Sub DeleteCCByTag()
    Dim oThisdoc As Word.Document
    Dim oCC As ContentControl
    Dim oCCs As ContentControls
    
    Set oThisdoc = ActiveDocument
    Set oCCs = oThisdoc.SelectContentControlsByTag("DCC")
    
        For Each oCC In oCCs
        If oCCs.Count > 0 Then
        oCC.Delete False
    End If
    Next
    End Sub
    

    0 讨论(0)
提交回复
热议问题