View Single Post
 
Old 11-14-2013, 03:06 AM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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