#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
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) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
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? |
#4
|
||||
|
||||
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) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
|||
|
|||
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. |
#6
|
|||
|
|||
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
|
#7
|
|||
|
|||
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.? |
#8
|
|||
|
|||
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. |
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 |