![]() |
#1
|
|||
|
|||
![]()
Hello.
I have been trying to find some solution or workaround to this, but surprisingly (and annoyingly) it doesn't seem like anything I've found online can be used for my situation. I have a userform where there is a TextBox, let's say "TextBox01". In it, the user would input a series of numbers, and each number would always refer to certain words. For example, number "01" would refer to "broken left arm", "02" would refer to "broken right arm", and so on. With plenty of bones to break, the list is quite long, sitting at about 50 possible numbers, each of which would have to be then "converted" (via find-and-replace or any similar method) into words. The "converted" (replaced) text would then appear into TextBox02, and then further processed to eventually be inserted into a bookmark, Bookmark01. I initially had success using this formula into TextBox01: Me.TextBox02 = Replace(Me.TextBox01, "01", "broken left arm") I was baffled to find out that one of these is just about all the program can handle. If I place two of them, only the second one will be applied (only the second number will be found-and-replaced); if I place three or more the program will crash as soon as I type the third number. Anyway, I've searched on google for hours and found lots of similar cases, but never one where they do this exact thing. Sometimes the code is for Excel (like, 80% of the time), sometimes it's for the whole document, sometimes it's for TextBoxes in the document but not for TextBoxes in the userform, ... "Frustrating" doesn't even begin to describe my experience with it, as this seems like an extremely simple thing to do, and yet it seems there is no easy function where you can just make a list of all the replacements you need. The way the program crashed was particularly infuriating, as I'm sure something as simple as finding and replacing text cannot require so much "power" that three requests at once would blow up a whole code. Before this I had tried writing a few hundreds of "if -> then" statements to manually replace the text that way, and THAT worked instantly without a hiccup. Like the infomercials say though, there has to be a better way. |
#2
|
||||
|
||||
![]()
Why are you even using a userform text box for this? Surely a combobox would make more sense? You could then have two columns in the list box, one for the number, the other for the description. You can choose whether or not to display the second column, if the users know what the numbers refer to. If you have the list in Excel, you can read the values into the listbox. See example attached. Save both items in the same folder for the list to work.
I also suggest using content controls rather than bookmarks as they are much less likely to be accidentally deleted. see https://www.gmayor.com/insert_content_control_addin.htm
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
laith93 | Word VBA | 7 | 12-13-2021 08:11 PM |
Userform textbox control missing/invisible; can't find, use or replace it; how to salvage work on a | marceepoo | Word VBA | 8 | 05-01-2020 09:56 PM |
![]() |
Gartholameau | Word VBA | 2 | 01-20-2019 04:56 PM |
![]() |
kvnrao | Word VBA | 7 | 11-02-2018 06:28 PM |
![]() |
Dave T | Word VBA | 2 | 07-16-2015 11:23 PM |