PDA

View Full Version : Content control combobox



max76
04-12-2017, 10:04 AM
Hi everyone,

I'm relatively new to VBA and I need your help since I couldn't find any solution anywhere. I created a document on Word 2010 with content control comboboxes containing eachdifferent items (one has about 90 items to choose from). When the user expands the dropdown list the WHOLE screen is covered with all the entries that fit in the screen and this is not very user-friendly because the user must be able to see what's behind on the screen in order to choose the correct item.

My question is: is there a way to limit the number of displayed items (for example the first 20) when the dropdown list is collapsed?

Thank you very much in advance for your support.

Massimo

gmaxey
04-12-2017, 05:11 PM
No there is not.

max76
04-12-2017, 10:57 PM
Hi Greg,

Thank you for your prompt reply
It's really sad how Microsoft omitted a few useful features regarding content controls.

Have a nice day

Massimo

macropod
04-13-2017, 03:51 AM
If fail to see how limiting the display to 20 items (for example) - at least 19 of which won't have been selected - when the dropdown list is collapsed would be helpful or how it might be one of 'a few useful features regarding content controls'. Conversely, the ability to apply such a limit when the dropdown list is expanded might be useful on the rare occasion - but one shouldn't expect Microsoft (or any other supplier) to design everything it produces for things that would rarely be used unless its clientele has very deep pockets.

max76
04-13-2017, 04:23 AM
Hi Paul,

Thank you for your email. I read my initial post and I realized that I meant "collapsed" instead of "expanded". The point is that my comboboxes have more than 50 items to choose from and 90% of these items are almost 255 characters long and therefore when the user expands the list the whole screen is covered. The users use a screen that is split into 2 horizontal halves: in the half above the user can review the different PDF documents to check and in the half below the Word document to check all the errors selecting them from the dropdown list. Therefore having a list that covers the whole screen makes the review process a little bit more annoying. That's why I was wondering if there was a way to limit the height of the "scrolling area" to a limited number such as 20 so that the upper part of the screen is not hidden.

Thank you.

Regards

Massimo

macropod
04-13-2017, 04:45 AM
I think Greg's already answered that.

Something that might help is to reduce the point size of the font and/or the size of the font itself (e.g. Arial Narrow) used in the dropdown. Although that won't help much vertically with 99 items, it would reduce the width required for the longer strings. Resizing and font changing could be made dynamic, via a pair of ContentControlOnEnter and ContentControlOnExit macros, so you could have a standard size for the prompt/output and a reduced size for the duration of its usage.

Paul_Hossler
04-13-2017, 05:17 AM
Could you use a non-modal userfrom instead of a content control as a workaround?

gmaxey
04-13-2017, 05:33 AM
I think Paul is suggesting something like this. I've done it before and it works relatively well.

In the document object module add the following. For this example my CC with the long list of items is titled "Big List" and it is a combbox CC with the default placeholder and first list item.


Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
Select Case ContentControl.Title
Case "Big List"
UserForm1.Show vbModeless
End Select
lbl_Exit:
Exit Sub
End Sub

Add a userform UserForm1 with a single combobox. In it, add this code:


Option Explicit

Private Sub ComboBox1_Change()
If Not ComboBox1.Value = ActiveDocument.SelectContentControlsByTitle("Big List").Item(1).PlaceholderText Then
ActiveDocument.SelectContentControlsByTitle("Big List").Item(1).Range.Text = ComboBox1.Value
End If
lbl_Exit:
Exit Sub
End Sub
Private Sub UserForm_Initialize()
Dim lngIndex As Long
For lngIndex = 2 To ActiveDocument.SelectContentControlsByTitle("Big List").Item(1).DropdownListEntries.Count
ComboBox1.AddItem ActiveDocument.SelectContentControlsByTitle("Big List").Item(1).DropdownListEntries(lngIndex).Value
Next
ComboBox1.Value = ActiveDocument.SelectContentControlsByTitle("Big List").Item(1).PlaceholderText
lbl_Exit:
Exit Sub
End Sub

gmaxey
04-13-2017, 05:36 AM
The lack of a contentcontrol change event is a far more egregious oversight.

max76
04-13-2017, 11:04 PM
Hi everyone,

thank you so much for your very prompt replies. As I said before this is the first time I've used a forum on vba and it's great to know one can count on professionals ready to help.

Greg thank you a lot for your code. That's an excellent workaround solution for my issue! And I totally agree with you on the lack of a CC change event!! That's really bad.

Have a wonderful Easter weekend

Massimo

Paul_Hossler
04-14-2017, 05:59 AM
Very imperfect workaround for missing _Change event

Could be made more robust




Option Explicit

Dim aCC As Variant

Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
Dim i As Long

For i = 1 To ThisDocument.ContentControls.Count
If aCC(i, 1) = ContentControl.Title Then
aCC(i, 2) = ThisDocument.ContentControls(i).Range.Text
Exit For
End If
Next i
End Sub


Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim i As Long

For i = 1 To ThisDocument.ContentControls.Count
If aCC(i, 1) = ContentControl.Title Then
If aCC(i, 2) <> ThisDocument.ContentControls(i).Range.Text Then
aCC(i, 2) = ThisDocument.ContentControls(i).Range.Text
Call CC_Changed(ContentControl)
Exit For
End If
End If
Next i
End Sub


Private Sub Document_Open()
Dim i As Long

ReDim aCC(1 To ThisDocument.ContentControls.Count, 1 To 2)

For i = 1 To ThisDocument.ContentControls.Count
aCC(i, 1) = ThisDocument.ContentControls(i).Title
aCC(i, 2) = ThisDocument.ContentControls(i).Range.Text
Next I

End Sub

Private Sub CC_Changed(ByVal CC As ContentControl)
MsgBox CC.Title & " was changed to " & CC.Range.Text
End Sub