Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-14-2013, 03:06 AM
macropod's Avatar
macropod macropod is offline Deleting a table from a content control -- preserving the content control Windows 7 32bit Deleting a table from a content control -- preserving the content control Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by BrainSlugs83 View Post
I was unaware of this requirement about content controls requiring empty paragraphs in them.
It's not that content controls require empty paragraphs, but that inserting a table into one (through the UI) inserts a paragraph before and after the table.
Quote:
Again, you can delete the trailing paragraph from within Word's UI (I posted the steps above).
I can't see those steps anywhere. I'm curious as to how you're deleting the paragraph break after the table in the content control, especially if the content control is protected against deletion. Indeed, if the content control is protected against deletion, I can't even delete the paragraph break that gets inserted before the table.

The only way I can get a table into a content control without the paragraph before and after the table is to first create the table, then select it and insert the content control. That is the reverse of how one would ordinarily insert these into a document. AFAIK, if the document has the content controls in place before the table is added and the applicable document protection is used, it is not possible for a user to do this - they would have to remove the protection and the content control, insert the table then reinsert the content control.
Quote:
At any rate, allowed or not -- Word doesn't prevent users from doing it, so I have to account for it.
Until I know how it's done without doing the above, I can't really say how one might protect against it, though a ConentControlOnExit macro could probably be used to Undo that action in most cases.
Quote:
if the content control is a child content control of a parent, and it happens to be the very last piece of content in the parent (i.e. the parent can contain tables, other content controls, paragraphs, etc., etc. but there is zero content after the final child control)...

In this situation, calling nothing but ".ConvertToText" does almost exactly what it should -- it converts the Table to text, but it moves the child control outside of the parent.

I suppose I can detect this watching for a change in "cc.ParentContentControl" -- but then I'd have to undo it (what if I'm in the middle of an UndoRecord, I don't want to undo the whole thing...) -- and also, I have to figure out a way to prevent the removal of the content control... put a paragraph after it, somehow, seems to do the trick... ugh, it just gets super hairy from there. :-/
Perhaps the safest way is to delete the content control and its table, then recreate the content control:


Code:
Sub DelCCTbl()
Dim Rng As Range, i As Long, CCtl As ContentControl, CCType As Long, CCTtl As String, CCTag As String, bProt As Boolean
With ActiveDocument
  With .ContentControls(1)
    CCType = .Type
    CCTag = .Tag
    CCTtl = .Title
    bProt = .LockContentControl
    .LockContentControl = False
    .Range.Characters.Last.Next.InsertBefore vbCr
    Set Rng = .Range
    .Delete
  End With
  Rng.Tables(1).Delete
  Rng.InsertAfter vbCr
  Set CCtl = .ContentControls.Add(CCType, Rng)
  With CCtl
    .Type = CCType
    .Tag = CCTag
    .Title = CCTtl
    .LockContentControl = bProt
  End With
End With
Set Rng = Nothing: Set CCtl = Nothing
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
content controls, deleting, tables



Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting a table from a content control -- preserving the content control Hierarchical content control ntjson Word VBA 1 04-04-2013 12:07 AM
Deleting a table from a content control -- preserving the content control Clearing content control tick box within table jillapass Word VBA 1 08-08-2012 04:58 PM
Word2010 check boxes and plain text content control boxes in same table fcsungard Word 5 06-01-2012 01:16 AM
Deleting a table from a content control -- preserving the content control Content control titles jillapass Word VBA 3 05-29-2012 06:11 AM
Retrieving content control value jillapass Word VBA 4 05-24-2012 05:07 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:52 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