Nitin Jadhav
Nitin Jadhav

Reputation: 527

Hide/Unhide text block in MS word depending on selection from dropdown list

We here have multiple products and I am creating a requirement document in MS Word for them. These products have few things in common and few features are specific to the individual product.

I want to create a single requirement document with a drop-down list containing product names in it. Whenever someone selects a product then the document should show the requirements in common to all product, the requirement specific to that product and hide requirements specific to other products.

For example- If there are two Products listed Product_1 and Product_2. Selecting Product_1 should show requirement related to Product_1 only and hide requirement related to Product_2

Here is what I searched and tried-

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
If ContentControl.Tag = "List" Then
   Bookmarks("Product_1").Range.Font.Hidden = False
   Bookmarks("Product_2").Range.Font.Hidden = False

   Select Case ContentControl.Range.Text
      Case "Product_1"
           Bookmarks("P2").Range.Font.Hidden = True
      Case "Product_2"
           Bookmarks("P1").Range.Font.Hidden = True
     End Select
End If
End Sub

But the problem is I cannot mark more than one text block under single Bookmark.

Let me know what is the other way to do this task?

Refer the screen shot. enter image description here

Thanks in advance

Nitin Jadhav

Upvotes: 0

Views: 3299

Answers (1)

DisplayName
DisplayName

Reputation: 13386

you should go the other way around:

  • bookmark any requirement specific to "Product_1" progressively with "Product_1_1", "Product_1_2", ...

  • bookmark any requirement specific to "Product_2" progressively with "Product_2_1", "Product_2_2", ...

  • and so on with other products

then change your event handler as follows:

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
    Dim bkm As Bookmark

    If ContentControl.Tag = "List" Then
        For Each bkm In ActiveDocument.Bookmarks
            bkm.Range.Font.Hidden = InStr(bkm.Name, "Product_") And Not InStr(bkm.Name, ContentControl.Range.Text)
        Next
    End If
End Sub

Upvotes: 2

Related Questions