#1
|
|||
|
|||
Content Control Dropdown Dependencies
Hi Paul,
I have used the macro that you supplied in https://www.msofficeforums.com/word-...own-lists.html and it works great. Is there a way to use the same macro except make it so depending on what I select from the dropdown menu, the output content can fill a row in a table in word? Instead of separating with a line break "|", is there a way to include a separator to acknowledge the cells and place values into different cells in a row? Thank you for your help |
#2
|
||||
|
||||
The value stored in the dropdown requires some form of separator to delineate the items. It's up to you what separator you use, but no separator will of itself tell Word to put something into a cell - you code has to do that. For example:
Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Dim i As Long, StrDetails As String With ContentControl If .Title = "Client" Then For i = 1 To .DropdownListEntries.Count If .DropdownListEntries(i).Text = .Range.Text Then StrDetails = .DropdownListEntries(i).Value Exit For End If Next With ActiveDocument.Tables(1).Rows(2) For i = 0 To UBound(Split(StrDetails, "|")) .Cells(i + 1).Range.Text = Split(StrDetails, "|")(i) Next End With End If End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Thanks a lot for your help. I now have it working. My last question is whether I can get certain values of the output to go into different rows. Using the example that was previously used on this thread, if I wanted the Phone number to go into one row and then the Address to go into the next row. I know I could do this by creating multiple drop down menus that reference different rows, but is there a way to do it with one dropdown list?
|
#4
|
||||
|
||||
Pretty much anything is possible, but I have no idea what your actual requirements are vis-à-vis what cells you want to update. The code I posted is for populating a single row. Code for populating a single column is no more difficult; it's only when you want a mix of rows & columns that things might get complicated.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
To be more specific, based on the dropdown at the top for the category someone selects, it should populate table 5, row 3 in my document with the first 5 values of the category's output content, then it should populate table 5, row 4 with the next 5 values of the output, and finally table 5, row 5 with the last 5 values of the output. These 3 different rows have different sets of information (one row is currency, another is numbers, the other text) but it is all based on what the user initially selects from the dropdown.
So I am trying to list all 15 of the values in the drop-down list properties and have it read to row 3 and then wrap around to row 4 and then row 5. There might be a better way of having each row call on the dropdown, but this way would still work. I hope that is more clear. Thank you. |
#6
|
||||
|
||||
If your table has 5 columns throughout, you could use:
Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Dim i As Long, StrDetails As String With ContentControl If .Title = "Client" Then For i = 1 To .DropdownListEntries.Count If .DropdownListEntries(i).Text = .Range.Text Then StrDetails = .DropdownListEntries(i).Value Exit For End If Next With ActiveDocument.Tables(5).Range For i = 0 To 14 .Cells(i + 11).Range.Text = Split(StrDetails, "|")(i) Next End With End If End With End Sub Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Dim i As Long, StrDetails As String With ContentControl If .Title = "Client" Then For i = 1 To .DropdownListEntries.Count If .DropdownListEntries(i).Text = .Range.Text Then StrDetails = .DropdownListEntries(i).Value Exit For End If Next With ActiveDocument.Tables(5) For i = 0 To 4 .Rows(3).Cells(i + 1).Range.Text = Split(StrDetails, "|")(i) Next For i = 5 To 9 .Rows(4).Cells(i - 4).Range.Text = Split(StrDetails, "|")(i) Next For i = 10 To 14 .Rows(5).Cells(i - 9).Range.Text = Split(StrDetails, "|")(i) Next End With End If End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Move to next content control | cksm4 | Word VBA | 13 | 07-02-2019 07:48 PM |
Clicking the selected Content Control checkbox returns wrong control in vba event | DougsGraphics | Word VBA | 2 | 06-24-2015 07:31 AM |
Deleting a table from a content control -- preserving the content control | BrainSlugs83 | Word Tables | 8 | 11-14-2013 03:06 AM |
Hierarchical content control | ntjson | Word VBA | 1 | 04-04-2013 12:07 AM |
Content control titles | jillapass | Word VBA | 3 | 05-29-2012 06:11 AM |