![]() |
#1
|
|||
|
|||
![]()
Hi
Great forum by the way I want to use the values of 4 content control drop downs, and put them together in one textbox content control? Example: Dropdown 1 value = a Dropdown 2 value = b Dropdown 3 value = c Dropdown 4 value = d Textbox showing a+b+c+d I know vba and content controls, but I don't know this Thanks |
#2
|
||||
|
||||
![]()
Assuming the dropdown controls you mentioned are the only ones in the document and your text content control has the title 'Output', you could use code in the document's 'This Document' module like:
Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Dim StrOutput As String, CtrlID As String If ContentControl.Type <> wdContentControlDropdownList Then Exit Sub For Each ContentControl In ContentControls If ContentControl.Type = wdContentControlDropdownList Then If ContentControl.Range.Text <> ContentControl.PlaceholderText Then StrOutput = StrOutput & ContentControl.Range.Text & "+" Else StrOutput = StrOutput & "N/A" & "+" End If End If If ContentControl.Title = "Output" Then CtrlID = ContentControl.ID Next StrOutput = Left(StrOutput, Len(StrOutput) - 1) ContentControls(CtrlID).Range.Text = StrOutput End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
Thanks for the answer
Unfortunately, there are also other dropdown lists in the document, can the code be rewritten to work with the tags or titles? |
#4
|
||||
|
||||
![]()
Yes, but that may not be necessary. If, for example, you inserted a Section break each side of the set of dropdowns, you could code the macro to examine the controls in only that Section. That would allow you to add/delete dropdowns in the Section at a later date without a code re-write.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
![]()
Then will the 'Output' content control box be located in another section. I feel more comfortable to be able to use tags or titles. If you may know a easy solution to use tags or titles, I would greatly appreciate it?
Anyway I'll try to work with the script you were so kind enough to give me. |
#6
|
||||
|
||||
![]()
If you give all the input dropdowns the title 'Input', you could use:
Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Dim StrOutput As String, CtrlID As String If ContentControl.Type <> wdContentControlDropdownList Then Exit Sub For Each ContentControl In ContentControls If ContentControl.Type = wdContentControlDropdownList Then If ContentControl.Title = "Input" Then If ContentControl.Range.Text <> ContentControl.PlaceholderText Then StrOutput = StrOutput & ContentControl.Range.Text & "+" Else StrOutput = StrOutput & "N/A" & "+" End If End If End If If ContentControl.Title = "Output" Then CtrlID = ContentControl.ID Next StrOutput = Left(StrOutput, Len(StrOutput) - 1) ContentControls(CtrlID).Range.Text = StrOutput End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
![]()
it works, but I notice that the result in the 'output' textbox, comes from the text in the "Display Name" column in the dropdowns, and not from the "Value" column?
I am bound to use customxmlpart to use the "Value" column? |
#8
|
||||
|
||||
![]()
I don't see where you've previously mentioned that the 'Value' column has anything other than the Display Name (default).
Getting values can be problematic if two or more have the same display names, as there's no vba for directly querying the displayed name's index #. Accordingly, one has to loop through all of them and compare the display name each against each list entry. Subject to that caveat, try: Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Dim StrOutput As String, CtrlID As String, i As Long If ContentControl.Type <> wdContentControlDropdownList Then Exit Sub For Each ContentControl In ContentControls With ContentControl If .Type = wdContentControlDropdownList Then If .Title = "Input" Then If .Range.Text <> .PlaceholderText Then For i = 1 To .DropdownListEntries.Count If .DropdownListEntries(i) = .Range.Text Then StrOutput = StrOutput & .DropdownListEntries(i).Value & "+" End If Next Else StrOutput = StrOutput & "N/A" & "+" End If End If End If If .Title = "Output" Then CtrlID = .ID End With Next StrOutput = Left(StrOutput, Len(StrOutput) - 1) ContentControls(CtrlID).Range.Text = StrOutput End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
![]()
If you "Input" CCs are mapped and all tagged "Input" then you could use something like this:
Code:
Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean) Dim strComposite As String Dim oCC As ContentControl Select Case CC.Tag Case "Input" For Each oCC In ActiveDocument.ContentControls If oCC.Tag = "Input" Then If oCC.XMLMapping.IsMapped Then strComposite = strComposite & " " & oCC.XMLMapping.CustomXMLNode.Text End If End If Next oCC MsgBox strComposite Case Else End Select End Sub |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
cksm4 | Word VBA | 13 | 07-02-2019 07:48 PM |
![]() |
ntjson | Word VBA | 1 | 04-04-2013 12:07 AM |
![]() |
jillapass | Word VBA | 3 | 05-29-2012 06:11 AM |
Retrieving content control value | jillapass | Word VBA | 4 | 05-24-2012 05:07 AM |
Calendar control accepts other values | JeJ | Word | 0 | 03-02-2011 03:38 PM |