Drop down list control value in vba

GDA

Joined
Mar 3, 2022
Messages
6
Reaction score
0
Hello to everyone again.
I'm sorry if I flood the forum with my request, but as said in another topic, I'm new to VBA and I'm trying to program a file to automate my office work, so that everyone can properly use it.

After the selection I'm facing another problem.
I have a drop down list of 5 elements named as protocols to follow to which I gave a hidden value through the property in the developer tab.
Then I write a macro to write the hidden value that I'll need for another instruction (because the if formula doesn't work in this file). I want the result in a specific cell of a chart, but the macro I find write the result in the row below the drop down list and it's not shown in the chart.
Another problem I'm facing is that I have more of those drop down list (like 4 or 5) and everyone has different elements with different hidden value, but I can only make the macro work for the first list.

Here's the macro
Sub Document_ContentControlOnExit()
Dim cc As ContentControl
Dim lngScore As Long
lngScore = 0
With ActiveDocument
For Each cc In ActiveDocument.ContentControls
If cc.Title = "Score" Then
Select Case cc.Range.Text
Case "Good"
lngScore = lngScore + 5
Case "Needs improvement"
lngScore = lngScore - 5
Case Else
lngScore = lngScore
End Select
End If
Next cc
.Variables("Score") = lngScore
.Range.Fields.Update
End With
End Sub

Thanks for the infinite help and patience to everyone
 

macropod

Microsoft MVP
Joined
Mar 2, 2012
Messages
578
Reaction score
50
For code to output content control values to other locations in the document, see:
and, for different elements from a selected item to be output to different content controls, see:

For a general idea of how to process multiple content controls with VBA, see:

As for your problem with the chart result going to the row below the drop down list, you need to keep in mind that the content control's index includes the prompt as the first item in the list. Either that or you're not correctly specifying which data row to write to.

For greater levels of complexity, see:

Dependent Dropdown Content Controls
and, for multiple levels of dependency:

Cascading Dropdown Content Controls

Content Control & Formfield Conditional Formatting

Creating and Tallying Mutually-exclusive Checkbox Content Controls

Adding a new row to a table in a document with content controls:
 
Last edited:

GDA

Joined
Mar 3, 2022
Messages
6
Reaction score
0
Thank a lot!
I'll use all those information to write a program that behave exactly as I need.
Thanks again, you have been very helpful
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top