Unfortunately what you want is is not what the code posted actually commands.
If the first item (Case 0) is selected then the code selects your choice from ListBoxCoCListBoxCoC. i.e. General Comments at bookmark1 OR Specific Comments at Bookmark 2. The ListBOXCOC.Text is whatever choice you select from that list box.
If you want to insert BOTH items, you don't need the listbox to select from between them.
You might want the list box to set values in the other lists, but as you have not shared your document nor indicated what they are for, it is not possible to guess how they should be used. You might want to look at Greg's web page on cascading list boxes, where the selection from one determines what is shown in another.
You will notice that the above code also calls FillBM to clear the bookmarks' contents before addressing them with the new data. The FillBM code below, is required should you wish to change you mind and change the inserted data. I assume that the Table autotext inserts a table. Tables inserted into ranges don't behave in quite the same was as texts and so it is necessary to delete the table(s) from the range before re-applying data to it - hence the modified version of my FillBM code from that you will find on my web site.Sub InsertExistingBuildingBlock() FillBM "EVTBookMark01", "" FillBM "EVTBookMark02", "" Select Case ComboBoxDocType.ListIndex Case Is = 0 'First item in list AutoTextToBM "EVTBookMark01", ActiveDocument.AttachedTemplate, "GeneralComments" AutoTextToBM "EVTBookMark02", ActiveDocument.AttachedTemplate, "SpecificComments" Case Is = 1 'Second item in list AutoTextToBM "EVTBookMark01", ActiveDocument.AttachedTemplate, "Table" 'Bookmark "EVTBookMark02" has no content with this option, unless you indicate here what it should be. Case Else 'Nothing selected End Select End Sub
If you want to insert different texts based on what is selected in the second list box then you need to indicate what happens for each selection e.g.Public Sub FillBM(strbmName As String, strValue As String) 'Graham Mayor - http://www.gmayor.com Dim orng As Range Dim i As Long With ActiveDocument On Error GoTo lbl_Exit Set orng = .Bookmarks(strbmName).Range If orng.Tables.Count > 0 Then For i = 1 To orng.Tables.Count orng.Tables(i).Delete Next i End If orng.Text = "" orng.Text = strValue orng.Bookmarks.Add strbmName End With lbl_Exit: Set orng = Nothing Exit Sub End Sub
Case Is = 0 'First item in list If ListBoxCoC.Text = "General Comments" Then AutoTextToBM "EVTBookMark01", ActiveDocument.AttachedTemplate, "GeneralComments" AutoTextToBM "EVTBookMark02", ActiveDocument.AttachedTemplate, "SpecificComments" Else 'Specific Comments has been selected so do something else End If




Reply With Quote
