Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 01-03-2017, 07:42 PM
wlcdo2 wlcdo2 is offline Windows 7 32bit Office 2013
Novice
 
Join Date: Jun 2016
Posts: 17
wlcdo2 is on a distinguished road
Default Content Control Checkboxes

Happy New Year everyone. I created a Word document that contains numerous ActiveX Checkboxes (50+) that I believe slows down the document upon opening. As I understand, Content Control Checkboxes is the better way to go. I'm therefore changing the Checkboxes over to Content Controls but I'm beginning to learn that programming actions is quite different and I'm at a road block. Here's a small sample of code for one set of actions that I can't get to work properly:


Code:
Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
    Application.ScreenUpdating = False
    If (ContentControl.Title = "ccHW" And ContentControl.Checked = True) Then
        Selection.GoTo What:=wdGoToBookmark, name:="HW"
        SelectionShow 'Calls this subroutine
        Me.lblTitle.ForeColor = wdColorRed
    Else
        Selection.GoTo What:=wdGoToBookmark, name:="HW"
        SelectionHide 'Calls this subroutine
    End If
    
    If (ContentControl.Title = "ccCS" And ContentControl.Checked = True) Then
        Selection.GoTo What:=wdGoToBookmark, name:="CS"
        SelectionShow
        Me.lblTitle.ForeColor = wdColorViolet
    Else
        Selection.GoTo What:=wdGoToBookmark, name:="CS"
        SelectionHide
    End If

End Sub
In that sample, I have 2 x Content Controls plus an ActiveX Label called lblTitle. If the user selects the Content Control called ccHW then a hidden bookmark is made visible and the Title colour changes; similarly if the user selects the Content Control ccCS a different hidden bookmark is made visible and the title colour changes.

With the ActiveX Controls, I used Select Case to nest the decision making & determine the CheckBox values, but I can't seem to do the same with Content Controls, I guess hence why my code above doesn't work too well.

What I'm looking to achieve is firstly convert all my ActiveX check boxes to Content Controls or to add the ActiveX Controls to a UserForm to speed up the document load time. Using the 2 x controls mentioned above, what I want to happen is:
If ccHW is true then display the ccHW bookmark content and colour the Label red.
If ccCS is true then display the ccHW bookmark content and colour the Label violet.
If both ccHW and ccCS are true, both bookmarks are visible & colour the label violet.
If neither ccHW or ccCS are true then both bookmarks are hidden and coloue the label blue (this last point isn't in my code above).

Someone's probably thinking, "What the...!!!!" at my attempt, but any points in the right direction is greatly appreciated.

Regards Corin.
Reply With Quote
  #2  
Old 01-03-2017, 10:23 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 2,198
gmayor is a jewel in the roughgmayor is a jewel in the roughgmayor is a jewel in the roughgmayor is a jewel in the rough
Default

You have to actually enter the content control from outside the control in order for the ContentControlOnEnter sub to fire. It doesn't operate on simply toggling the control. Thus the following should demonstrate.

Code:
Option Explicit

Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
    Select Case ContentControl.Title
        Case "ccHW"
            If ContentControl.Checked Then
                FillBM "HW", "This is the content of bookmark HW"
            Else
                FillBM "HW", ""
            End If
        Case "ccCS"
            If ContentControl.Checked Then
                FillBM "CS", "This is the content of bookmark CS"
            Else
                FillBM "CS", ""
            End If
    End Select
End Sub

Private Sub FillBM(strBMName As String, strValue As String)
'Graham Mayor - http://www.gmayor.com
Dim oRng As Range
    With ActiveDocument
        On Error GoTo lbl_Exit
        Set oRng = .Bookmarks(strBMName).Range
        oRng.Text = strValue
        oRng.Bookmarks.Add strBMName
    End With
lbl_Exit:
    Set oRng = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 01-03-2017, 10:49 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,526
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

You might also be interested in the demo documents in the following posts:
http://www.msofficeforums.com/word-t...html#post33489
http://www.msofficeforums.com/word-t...tml#post107008
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #4  
Old 01-05-2017, 05:52 PM
wlcdo2 wlcdo2 is offline Windows 7 32bit Office 2013
Novice
 
Join Date: Jun 2016
Posts: 17
wlcdo2 is on a distinguished road
Default

Thank you so much Graham. I used your code and now have a slightly better understanding of the ContentControl checkboxes. I'm think I'm going to leave a mixture of ContentCOntrols and ActiveX Controls in my document for now but will keep toiling away based on what I've learned from you.
Once again, may thanks.

Paul, Thanks too for your feedback and links that were provided.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Content Control Box dep7418 Word 2 12-18-2016 08:08 PM
Content Builder Using Checkboxes MauriceP Word 2 10-19-2015 09:49 PM
Clicking the selected Content Control checkbox returns wrong control in vba event DougsGraphics Word VBA 2 06-24-2015 07:31 AM
Deleting a table from a content control -- preserving the content control BrainSlugs83 Word Tables 8 11-14-2013 03:06 AM
Assigning Values to content control checkboxes and calculating results creative cathy Word Tables 13 10-07-2012 08:52 PM


All times are GMT -7. The time now is 07:41 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft