#1
|
|||
|
|||
dropdown list to create tables
Hi,
Is there a way to auto-create a table based on the selected drop down list in Word 2007? i.e Dropdown list Yes -> If user selects yes, the a 2 column 2 rows table will be created. No Thanks! |
#2
|
||||
|
||||
Yes. What kind of drop down list? What kind of content will the table have and is it to be editable, or just displayed?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Hi Paul,
A dropdown list with value yes and no only. If I select 'yes', then a table should appear (see attached image). It should be editable. Thank you in advance! |
#4
|
||||
|
||||
That tells me what the options are, but not what kind of dropdown you're using, which could be any of a formfield, content control or ActiveX control.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
It is content control dropdown but we can change it to any kind of dropdown as long as the desired table will appear when we select the 'Yes' option.
|
#6
|
||||
|
||||
Try the attached. The document has a dropdown content control titled 'Demo' and a bookmark named 'Tbl' where the table might go. Pressing Alt-F11 will expose the VBA code that drives the process when the content control is exited.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
Thank you so much!
|
#8
|
|||
|
|||
Hi macropod, how can I insert a content control dropdown list below the "Account" text? I tried modifying the code but it always inserting the dropdown list outside the table.
Appreciate your help. |
#9
|
||||
|
||||
Try, for example:
Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean) Dim Tbl As Table, Rng As Range If CCtrl.Title <> "Demo" Then Exit Sub Application.ScreenUpdating = False Set Rng = ActiveDocument.Bookmarks("Tbl").Range Select Case CCtrl.Range.Text Case "Yes" If Rng.Tables.Count > 0 Then Exit Sub Set Tbl = Rng.Tables.Add(Range:=Rng, NumRows:=1, NumColumns:=2) With Tbl .AllowAutoFit = False .Borders.Enable = True .Rows.Height = InchesToPoints(0.75) .Columns(1).Width = InchesToPoints(2.5) .Columns(2).Width = InchesToPoints(3) With .Cell(1, 1).Range .Text = "Account:" & vbCr & " " .ContentControls.Add Type:=wdContentControlText, Range:=.Paragraphs(2).Range.Characters.First .ContentControls(1).Range.Text = "" .Paragraphs(1).Range.Font.Bold = True End With With .Cell(1, 2).Range .Text = "Remarks:" & vbCr .Paragraphs(1).Range.Font.ColorIndex = wdTurquoise End With End With Case Else If Rng.Tables.Count > 0 Then Rng.Tables(1).Delete End Select Set Tbl = Nothing: Set Rng = Nothing Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Selection of a dropdown creates another dropdown wih the list | krishnamurthy.ka2810 | Word VBA | 1 | 04-26-2018 11:44 PM |
Dropdown content control and tables | hrzagi | Word | 1 | 12-17-2017 09:38 PM |
Change colours in different tables based on dropdown selections | kevinbradley57 | Word VBA | 10 | 08-09-2017 03:54 PM |
excel2016: can't create dropdown | afik | Excel | 4 | 11-13-2016 01:38 PM |
Help!! Dropdown List | christo16 | Word | 1 | 06-29-2015 05:18 AM |