0

I have a VBA macro that will auto populate a document with content control quick parts that have blocks of text with other content controls within them.

I'm attempting to write a VBA macro that will sift through an entire document to remove the quick part content control box around each inserted quick part so it no longer exists but still keeps the contents that were produced by the quick part and also not remove the content controls within the existing quick part.

So far I have only been able to create a macro that would remove all content controls but I don't know the specific code that would target removing the quick part only but still keeping the quick part contents.

FYI, I can manually do this by right clicking anywhere inside the quick part(besides a content control within the quick part) and it will allow me to remove the quick part content control.

2
  • What research/tries have you done about using VBA for that?
    – harrymc
    Commented Mar 19 at 20:10
  • I have looked at different SuperUser/Stack Exchange pages along with people such as Greg Maxey and couldn't find anything that could assist. Normally what I do is click the right button on the mouse and I can remove the quick part content control box. So what I attempted to do was do a macro recording and do the same to see what code it would right, but when recording a macro it doesn't open the right click menu. I did however add the action that is done through the right click menu as a button on my ribbon but each content control had its own unique number so it wasn't effective Commented Mar 27 at 15:19

1 Answer 1

0

Something like:

Sub removeBuildingBlockCCs()
Dim cc as Word.ContentControl
For Each cc In ActiveDocument.ContentControls
  If cc.Type = wdContentControlBuildingBlockGallery Then
    cc.Delete
  End If
Next

Incidentally, to use a popup context menu when using the Macro recorder, you can usually use either the "context menu" key on a Windows keyboard (looks like a context menu, mine is to the right of the Windows key). AUIU you are supposed to be able to use shift-F10 to do the same, but it doesn't seem to work here, don't know why.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .