Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 03-10-2015, 12:31 AM
Catty Catty is offline Windows 7 32bit Office 2010 32bit
Advanced Beginner
 
Join Date: Nov 2013
Posts: 39
Catty is on a distinguished road
Default Macro to unlock content controls


Hi

I have code that unlocks a locked content control in order for me to delete it via code. The only problem I have is that I am unable to make this work for content controls that are inside a textbox. Below is the code i'm using.

Code:
Sub UnlockCControls()
Dim oCC As ContentControl
For Each oCC In ActiveDocument.ContentControls
oCC.LockContentControl = False
Next oCC
End Sub
Please help!
Reply With Quote
  #2  
Old 03-10-2015, 01:10 AM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 2,719
gmayor is just really nicegmayor is just really nicegmayor is just really nicegmayor is just really nice
Default

Text boxes are not in the text layer of the document so your macro doesn't see them. The following however should work

Code:
Sub UnlockCControls()
Dim oStory As Range
Dim oCC As ContentControl
    For Each oStory In ActiveDocument.StoryRanges
        For Each oCC In oStory.ContentControls
            oCC.LockContentControl = False
        Next oCC
        If oStory.StoryType <> wdMainTextStory Then
            While Not (oStory.NextStoryRange Is Nothing)
                Set oStory = oStory.NextStoryRange
                For Each oCC In oStory.ContentControls
                    oCC.LockContentControl = False
                Next oCC
            Wend
        End If
    Next oStory
lbl_Exit:
    Set oStory = Nothing
    Set oCC = 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 03-10-2015, 01:45 AM
Catty Catty is offline Windows 7 32bit Office 2010 32bit
Advanced Beginner
 
Join Date: Nov 2013
Posts: 39
Catty is on a distinguished road
Default

Thanks for your response Graham.

I have tested the macro and it's still not unlocking the controls within the text box (Unlocks for those outside the textbox though). Could the fact that the controls have different tags and tittles make a difference?
Reply With Quote
  #4  
Old 03-10-2015, 02:16 AM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 2,719
gmayor is just really nicegmayor is just really nicegmayor is just really nicegmayor is just really nice
Default

Hmmm. It works here as expected. The problem most probably relates to the use of text boxes, when invariably table cells or frames make better choices for putting fields in boxes. Text boxes are essentially graphical objects.

Nevertheless the posted code should work in a text box in the body of a document.

Can you post your document?
__________________
Graham Mayor - MS MVP (Word)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 03-10-2015, 02:28 AM
Catty Catty is offline Windows 7 32bit Office 2010 32bit
Advanced Beginner
 
Join Date: Nov 2013
Posts: 39
Catty is on a distinguished road
Default

Thanks so much for your assistance Graham.

I apologize, I tested the macro incorrectly

Your macro works beautifully, and I have modified it to not only unlock the content controls, but to also delete the cover page and re-lock all controls that should not be deleted.

Thank you so much for your assistance.
Reply With Quote
  #6  
Old 03-10-2015, 03:08 PM
gmaxey gmaxey is offline Windows 7 32bit Office 2010 (Version 14.0)
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 843
gmaxey will become famous soon enough
Default

If you are interested, you can download an add-in that makes doing most of this sort of stuff child's play: http://gregmaxey.com/word_tip_pages/...rol_tools.html
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #7  
Old 03-10-2015, 05:09 PM
gmaxey gmaxey is offline Windows 7 32bit Office 2010 (Version 14.0)
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 843
gmaxey will become famous soon enough
Default

Catty,

I would like to see your code. If you have code to delete a CC, then why don't you use the same code to unlock it first.?
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #8  
Old 03-18-2015, 02:08 AM
Catty Catty is offline Windows 7 32bit Office 2010 32bit
Advanced Beginner
 
Join Date: Nov 2013
Posts: 39
Catty is on a distinguished road
Default

Hi Greg,

Thanks for your response. The code is included in the thread. The code did infact unlock content controls but not those controls placed inside a text box or a container of some sort.

I needed the code to specifically unlock those controls placed in a container.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
When content controls are deleted, my macro does not work as I would like. harry.ayre Word VBA 2 02-23-2015 10:35 AM
Cant type into content controls in a form after protecting document using macro rgburridge Word VBA 4 01-27-2015 02:37 PM
Word 2010 Macro Enabled Template with Content Controls keen1598 Word VBA 7 01-29-2014 03:17 PM
Content Controls Sammie0Sue Word 6 11-06-2013 10:56 PM
Macro to link 2 content controls bortonj88 Word VBA 2 08-21-2012 06:24 AM


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


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