Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-13-2022, 07:17 AM
ericliu24 ericliu24 is offline How to reset building block gallery content control Windows 10 How to reset building block gallery content control Office 2019
Novice
How to reset building block gallery content control
 
Join Date: Mar 2022
Location: China
Posts: 21
ericliu24 is on a distinguished road
Default How to reset building block gallery content control

For autotext or dropdownlist, we could set .range.text ="" to reset them.

But for building block gallery content control (category is table), how to do it?

Many thanks.

Sub ResetCC()
Dim ct1 As ContentControl
Dim String1 As String
For Each ct1 In ActiveDocument.ContentControls
If ct1.Type=wdContentControlDropdownList Then
ct1.Type = wdContentControlText
ct1.Range.Text = ""
ct1.Type = wdContentControlDropdownList

End If

If ct1.Type=wdContentControlBuildingBlockGallery Then
' how to reset?
End If



Next
End Sub
Reply With Quote
  #2  
Old 04-13-2022, 07:45 PM
Guessed's Avatar
Guessed Guessed is offline How to reset building block gallery content control Windows 10 How to reset building block gallery content control Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,159
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Try this version
Code:
Sub ResetCCs()
  Dim aCC As ContentControl, iType As Integer
  For Each aCC In ActiveDocument.ContentControls
    With aCC
      Select Case .Type
        Case wdContentControlText, wdContentControlRichText, wdContentControlDate
          .Range.Text = ""
        Case wdContentControlComboBox, wdContentControlDropdownList
          .DropdownListEntries(1).Select
        Case wdContentControlCheckBox
          .Checked = False
        Case wdContentControlBuildingBlockGallery
          iType = .Type
          .Type = wdContentControlRichText
          .Range.Text = ""
          Do While .Range.Tables.Count > 0
            .Range.Tables(1).Delete
          Loop
          .Type = iType
      End Select
    End With
  Next aCC
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia

Last edited by Guessed; 04-13-2022 at 11:30 PM. Reason: Amended to deal with tables in Building Block CCs
Reply With Quote
  #3  
Old 04-13-2022, 11:17 PM
ericliu24 ericliu24 is offline How to reset building block gallery content control Windows 10 How to reset building block gallery content control Office 2019
Novice
How to reset building block gallery content control
 
Join Date: Mar 2022
Location: China
Posts: 21
ericliu24 is on a distinguished road
Default

Many thanks Andrew,

If the building block is table , .Range.Text = "" throws the error 6192, inappropriate range.

Any fix for this ?
Reply With Quote
  #4  
Old 04-13-2022, 11:31 PM
Guessed's Avatar
Guessed Guessed is offline How to reset building block gallery content control Windows 10 How to reset building block gallery content control Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,159
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I've amended the code to remove any tables which might be in the Content Control when you try to clear it.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 04-14-2022, 06:49 AM
ericliu24 ericliu24 is offline How to reset building block gallery content control Windows 10 How to reset building block gallery content control Office 2019
Novice
How to reset building block gallery content control
 
Join Date: Mar 2022
Location: China
Posts: 21
ericliu24 is on a distinguished road
Default

The code erases the category and type of the content control. I would like all the properties remain the same but reset it to the "unselected" initial status.

please see the attached file
Attached Files
File Type: dotm reset-bb-gallery-cc-table.dotm (25.3 KB, 6 views)
Reply With Quote
  #6  
Old 04-14-2022, 11:38 AM
Italophile Italophile is offline How to reset building block gallery content control Windows 11 How to reset building block gallery content control Office 2021
Expert
 
Join Date: Mar 2022
Posts: 539
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

There are tools available in the Visual Basic Editor to help you answer questions like this: IntelliSense, the Object Browser, online help.

Code:
Sub ResetCCs()
    Dim aCC As ContentControl, iType As Integer
    Dim bbCat As String, bbType As Long
    For Each aCC In ActiveDocument.ContentControls
        With aCC
            Select Case .Type
                Case wdContentControlText, wdContentControlRichText, wdContentControlDate
                    .Range.Text = ""
                Case wdContentControlComboBox, wdContentControlDropdownList
                    .DropdownListEntries(1).Select
                Case wdContentControlCheckBox
                    .Checked = False
                Case wdContentControlBuildingBlockGallery
                    iType = .Type
                    bbType = .BuildingBlockType
                    bbCat = .BuildingBlockCategory
                    .Type = wdContentControlRichText
                    .Range.Text = ""
                    Do While .Range.Tables.Count > 0
                        .Range.Tables(1).Delete
                    Loop
                    .Type = iType
                    .BuildingBlockType = bbType
                    .BuildingBlockCategory = bbCat
            End Select
        End With
    Next aCC
End Sub
Attached Images
File Type: png IntelliSense.png (6.7 KB, 14 views)
File Type: png Object Browser.png (77.2 KB, 14 views)
Reply With Quote
  #7  
Old 04-15-2022, 06:16 AM
ericliu24 ericliu24 is offline How to reset building block gallery content control Windows 10 How to reset building block gallery content control Office 2016
Novice
How to reset building block gallery content control
 
Join Date: Mar 2022
Location: China
Posts: 21
ericliu24 is on a distinguished road
Default

It works.
Can't thank you enough.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
collabrate bulding block gallery or text content samouti Word 7 05-07-2019 06:56 AM
Reference a Building block gallery control from another Field and insert text using If logic Flynny Word VBA 3 07-30-2018 08:34 PM
How-to: Add a quickpart, field or Building Block Gallery Content Control based on a UserForm HighSierra Word VBA 0 05-06-2015 08:20 PM
Using Building Block Gallery Content function on a form with restricted editing wes228 Word VBA 1 08-28-2014 08:14 AM
how to make building block content control determine bb to display elsewhere jamles12 Word VBA 5 11-16-2013 11:38 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:55 AM.


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