VBA ParentContentControl.Ungroup (error 91)

D

drichird

I have a small table based form, some text to prompt for user input in a few
cells, some (new Word 2007) 'plain text content control's in the other cells.
Form has been protected with [developer tab][group pulldown][group] so user
can only input into controls.

If I run the macro recorder on these commands: [select all][developer
tab][group pulldown][ungroup] to remove the 'group' protection from the text
fields, and then try to run that macro, I get an error 91 (Object Variable or
With Block variable not set) on the macro VBA line:

ParentContentControl.Ungroup

My goal is to programmatically ungroup my group protected form when certain
cells need to be deleted with cells(...).delete, based on certain user input
into the form.
 
C

Cindy M.

Hi =?Utf-8?B?ZHJpY2hpcmQ=?=,
If I run the macro recorder on these commands: [select all][developer
tab][group pulldown][ungroup] to remove the 'group' protection from the text
fields, and then try to run that macro, I get an error 91 (Object Variable or
With Block variable not set) on the macro VBA line:

ParentContentControl.Ungroup
Possibly, it's a problem with where the selection is when you run this bit of
code. Ungroup can only work on a content control that's grouping other content
controls. "ParentContentControl" is not a special object on the document - it
could be any content control.

The following wouldn't be the most efficient way to go about it, but it's a good
was to test if the command will work:

Sub UngroupCCinDoc()
Dim cc As Word.ContentControl

For Each cc In ActiveDocument.Contentcontrols
If cc.Type = wdContentControlGroup Then
cc.Ungroup
End If
Next
End Sub

Better, though would be a way to identify the group control, or any control in
the group (because through that you can reach ParentcontenControl).

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top