Can drop down menus make different tables visible?

Hello,

I am looking to have a drop down menu contain 2-3 options.  Depending on what option is selected i would like a different table to become visible. 

for example:

The drop down menu would contain, approved, pending more testing, rejected.

if someone is to select the approved drop down a table would become visible with columns for certain information contacts and related information

if someone is to select the pending more testing drop down a table would appear with columns more suited for the selection to write contacts/related information. 

Right now the word document currently contains all 3 tables for the 3 selections and causes quite a messy looking document that I would like to clean up.  Any help on this would be fantastic!

Thank you!!


By dropdown menu, do you mean a content control dropdown box in the document?  If so then proceed as follows.


1.  Add the dropdown and define it's list members (here I've used Table A, Table B ...).

2.  Create BuildingBlocks of each of the three tables.  Use the AutoText gallery in the attached template.  Name the building blocks "Table A, Table B, ...

3.  Add the following code to the ThisDocument module of the template.

4.  Add a bookmark "bmTable" where the table needs to appear.



Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
Select Case CC.Title
  Case "Table"
    Select Case CC.Range.Text
      Case "A"
        UpdateBookmark "bmTable", "Table A"
      Case "B"
        UpdateBookmark "bmTable", "Table B"
      Case "C"
        UpdateBookmark "bmTable", "Table C"
   End Select
 End Select
End Sub


Sub UpdateBookmark(BmkNm As String, Optional strATName As String)
Dim BmkRng As Range
With ActiveDocument
  If .Bookmarks.Exists(BmkNm) Then
    Set BmkRng = .Bookmarks(BmkNm).Range
    If strATName <> vbNullString Then
      On Error Resume Next
      BmkRng.Tables(1).Delete
      On Error GoTo 0
      Set BmkRng = ActiveDocument.AttachedTemplate.AutoTextEntries(strATName).Insert(Where:=BmkRng)
    Else
      BmkRng.Text = vbNullString
    End If
    .Bookmarks.Add BmkNm, BmkRng
  End If
End With
Set BmkRng = Nothing
End Sub


When the user selects the table from the CC and exist, the appropriate table will appear at the bookmark.

Greg Maxey
***
Death smiles at us all, but all a man can do is smile back.


For more help with Word visit:
http://gregmaxey.com/word_tips.html

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Hello Greg,

Thank you for the reply.   I am doing my best to follow your instructions but I am brand new to programming MS word 2007.  It sounds like what you described is exactly what I'm looking to do. 

if possible,  could you provide these directions in a "for dummies" kind of method. 

I truly appreciate any help you can provide me. 

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

I certainly don't mean to sound pompous or arrogant, but I really don't know what else I can do to make it clearer.  Maybe this will help:  See: http://gregmaxey.mvps.org/word_tip_pages/installing_employing_macros.html for instructions to employ the VBA code provided above.

 

Greg Maxey
***
Death smiles at us all, but all a man can do is smile back.


For more help with Word visit:
http://gregmaxey.com/word_tips.html

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Greg,

I was having trouble navigating throughout the modules. I think I almost have this set.

Right now when i select the drop down option I am getting the error

Run-time error '5941'"
the requested member of the collection does not exist.

When i click debug this is what is highlighted
 Set BmkRng = ActiveDocument.AttachedTemplate.AutoTextEntries(strATName).Insert(Where:=BmkRng)

When i created the building blocks i selected
Gallery: autotext
Category: general
Save in: building blocks
Options: insert content only

I am thinking the building blocks are saved/attached incorrectly.  When you mentioned attached template, is that a specific location I need to bring up?

I truly appreciate the help on this. Thanks Again!

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

AttachedTemplate is the template attached to the document. If your document began life as a new blank document, then that template is Normal.  If it began life from some other template (e.g., My Letterhead Template, then that template is most likely the attached template.


When you create and save the buildingblock, save it in the name of the attached template, not BuildingBlocks.


Greg Maxey
***
Death smiles at us all, but all a man can do is smile back.


For more help with Word visit:
http://gregmaxey.com/word_tips.html

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Greg,

Thank you very much for your help on this.  I was able to get this function to properly work.  And you did make it pretty much idiot proof to do.  Just took me some time to figure out how to navigate through Word and macros.

once again, thank you

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

You're welcome.  I remember the time when I likewise struggled with macros.  It is just hard to think like that now :-(


Greg Maxey
***
Death smiles at us all, but all a man can do is smile back.


For more help with Word visit:
http://gregmaxey.com/word_tips.html

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Greg,

I have one more question for you regarding these tables.  While the function is working properly and loading the table.  The Table formatting does not copy over. 

When I go and manually insert the building block, the formatting is saved (bold, italics, font size, etc)

Why does this not copy over into the Table?  is there something I need to do to get this to happen.

Once again, I am truly appreciative of the help you've given me on this


Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated April 2, 2024 Views 1,654 Applies to: