Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #8  
Old 01-14-2022, 04:00 AM
gmayor's Avatar
gmayor gmayor is offline VB Script using Content Control Windows 10 VB Script using Content Control Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,138
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If there is no manual intervention, you need a different approach. Lose the code in the ThisDocument module and create a new module and add the following.
Code:
Option Explicit

Sub FileSave()
    Document_UpdateContentControls
    ActiveDocument.Save
End Sub

Sub Document_UpdateContentControls()
Dim oCC As ContentControl
    For Each oCC In ActiveDocument.ContentControls
        Select Case LCase(oCC.Title)
            Case Is = "comsystem"
                FillCB "Int4", False
                FillCB "BRY5", False
                FillCB "BVW", False
                FillCB "Con3", False
                If InStr(1, LCase(oCC.Range.Text), "test") > 0 Then
                    FillCB "Int4", True
                    FillCB "Con3", True
                End If
                If InStr(1, LCase(oCC.Range.Text), "actual") > 0 Then
                    FillCB "BRY5", True
                    FillCB "BVW", True
                End If
            Case Else
        End Select
    Next oCC
    Set oCC = Nothing
End Sub

Private Sub FillCB(strCCTitle As String, bValue As Boolean, Optional bLock As Boolean = False)

Dim oCC As ContentControl
    On Error GoTo lbl_Exit
    For Each oCC In ActiveDocument.ContentControls
        If LCase(oCC.Title) = LCase(strCCTitle) Then
            oCC.LockContents = False
            oCC.Checked = bValue
            oCC.LockContentControl = True
            If bLock = True Then oCC.LockContents = True
            Exit For
        End If
    Next oCC
lbl_Exit:
    Set oCC = Nothing
    Exit Sub
End Sub

You need to be able to call the Document_UpdateContentControls macro - preferably from your automated script, but here it is called from a FileSave macro which intercepts the save command CTRL+S and runs the macro before saving.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
 

Tags
content control events, vba combobox, vba word



Similar Threads
Thread Thread Starter Forum Replies Last Post
VB Script using Content Control Change Value of a Content Control based on the value of another content Control jsc_msoffice Word VBA 2 05-21-2021 09:51 PM
VB Script using Content Control Content Control Dropdowns - How to duplicate the content control and allow a second choice ashleyf Word VBA 2 03-19-2020 09:11 AM
Content Control content deleted when re-uploading to SharePoint Peterson Word 5 06-27-2018 08:13 PM
VB Script using Content Control Clicking the selected Content Control checkbox returns wrong control in vba event DougsGraphics Word VBA 2 06-24-2015 07:31 AM
VB Script using Content Control Deleting a table from a content control -- preserving the content control BrainSlugs83 Word Tables 8 11-14-2013 03:06 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:33 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft