I am trying to write Word vba code that will insert a variety of different tables with multiple content controls when a selection is made from a drop down content control. I have tried writing the code several ways, but every time I tab to exit the drop down content control for the next content control, I get the error "Run-time error '4605': This method or property is not available because the current selection partially covers a plain text content control." The only time that I do not get this error is when I use the cursor to click away and do not click on a content control, then the code runs perfectly and generates the table with all the content controls. Below is a code that I have been using to test different ideas. I plan on protecting this document after the code has been completed to keep people from modifying the form. Thank you for any input!
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
If ContentControl.Tag = "ReturnType" Then
Dim tbl As Table
Dim rng As Range
Select Case ContentControl.Range.Text
Case "Selection 1"
Set rng = ActiveDocument.Content.Paragraphs(3).Range
Set tbl = rng.Tables.Add(rng, 3, 3)
tbl.cell(1, 2).Range.ContentControls.Add wdContentControlCheckBox
Case "Selection 2"
Set rng = ActiveDocument.Content.Paragraphs(3).Range
Set tbl = rng.Tables.Add(rng, 2, 2)
Case "Selection 3"
Set rng = ActiveDocument.Content.Paragraphs(3).Range
Set tbl = rng.Tables.Add(rng, 1, 1)
End Select
End If
End Sub
I have tried to generate the tables via using multiple If statements, Select Case statements, and referencing new sub statements. I just cannot seem to get this to run properly.