Super User Asked by Serdia on November 3, 2021
I need to enter some text based on dropdown selection in word.
But it only allow 255 characters.
Is there a way I can enter more than that?
Maybe there is a work around for that?
I did not find a lot of info about that.
Please, direct me to the right way.
The value can't have more than 255 characters and in any case is not shown in the document - even to do that you would have to "map" the content control to an element in a Custom XML Part, map a plain text content control to that element and put that control in the document.
So you have to do this some other way. There are several possibilities, each with their own advantages and disadvantages. e.g. a. put all your texts in Building Block entries in a specific Gallery (e.g. "Custom 1" and Category (e.g. one you create specifically for this control). b. use a legacy form field dropdown and a field that inserts the value you want depending on the value selected. c. "use VBA".
(a) and (b) are the only approaches I can think of that don't need VBA. As soon as you use VBA, there are a number of possibilities.
For (a), Building Block entries have to be in a Word template or special building block template. So if you want a single-file solution you have to make your document a .dotx not a .docx. AFAIK the building block mechanism is not available on Mac. You basically choose a (predefined gallery and create a category, put all the entries you want to display in the dropdown in that gallery/category, then set up the Building Block Content control's properties to use that gallery/category. The selected entry's content is displayed directly in the control. The building block names and content are displayed in the "dropdown". The names have a length limitation (32 characters I think).
For (b), you create a legacy formfield dropdown with the "display names" that you want, and set the form field to "calculate on exit". I think you are limited to 25 options. The display names are limited to something like 50 characters.
Then you set up one of more fields that display the text you want, using the "display name". At its simplest you could use one IF field for each dropdown value, so if the dropdown had values "abc", "def", "ghi" etc. you could use
{ IF "{ Dropdown1 }" = "abc" "The chunk of text you want for abc" "" }{ IF "{ Dropdown1 }" = "def" "The chunk of text you want for def" "" }
You then have to "protect the document for forms", which means that the user can't do any editing other than filling in the form. Or you can protect a section of the document, in which case the user gets to edit the remainder of the document, with some restrictions.
If you go the VBA route, let's assume you are going to use a Content Control dropdown. Then you need an event to run your VBA - you can either use a content control event or if you map your content control to a Custom XML Part, you can use a "Datastore" event (linked to the XML Part). Your VBA then needs to know where to display the text and what text to display.
So let's imagine your dropdown has Title dd1
, you are going to put your text in a plain text content control titled tb1
, and your dropdown's "display names" are my display name 1
, my display name 2
and so on. Then you can put the following VBA in your ThisDocument
module. This will "fire" when you click outside the dropdown control or tab out of it.
NB for this to work, tb1's "contents cannot be edited" property has to be unchecked
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim cc1 As ContentControl
Select Case ContentControl.Title
' the dropdown
Case "dd1"
' Assumes "tb1" exists
Set cc1 = ContentControl.Range.Document.SelectContentControlsByTitle("tb1")(1)
If ContentControl.ShowingPlaceholderText Then
' Resets tb1 to its placeholder text
cc1.Range.Text = ""
Else
Select Case ContentControl.Range.Text
Case "my display name 1"
cc1.Range.Text = "whatever text you want for abc"
Case "my display name 2"
cc1.Range.Text = "whatever text you want for def"
Case Else
'
End Select
End If
Set cc1 = Nothing
Case Else
'
End Select
End Sub
Personally I prefer to use content control mapping and the datastore events, but it is more complicated and I think the above approach should meet the requirement as you've described it.
Answered by user1079414 on November 3, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP