PLEASE TELL ME THIS IS POSSIBLE OR NOT POSSIBLE WITH A USERFORM TEXTBOX TEXT...

chazrab

Well-known Member
Joined
Oct 21, 2006
Messages
884
Office Version
  1. 365
Platform
  1. Windows
Title explains, as does image below. Tried and tried and tried, but could not do it with my own
vba experience. Below is just an image created to show what I want to do that will display as
shown when the userform is displayed.

I know this is possible in c# and/or probably VIsual Studio, but I don't want to spend time
learning either or both just to have a text string within a userform textbox be a certain color.

Please someone, let me know if further efforts to do this by me with the VBA app dev environment
will be a waste of time.

Thanks for anyone's help, comments and/or suggestions.
 

Attachments

  • RED TEXT STRING IN A USERFORM TEXTBOX.png
    RED TEXT STRING IN A USERFORM TEXTBOX.png
    16.7 KB · Views: 12

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
You cannot do that with a Textbox.
 
Upvote 0
Hi, the multiple text color is not possible using textbox but can do using additional control "Microsoft InkEdit Control" (see image)

Additional Controls.jpg


The output would be as below.

1654346768889.png


Below is the macro used to display the text inside double quotes in RED font.
  1. The InkEdit control name is inktext.
  2. Chr(34) is used for double quotes.

VBA Code:
Private Sub UserForm_Activate()
Dim firstpos As Integer, lastpos As Integer

inktext.Text = "And Jesus Said to him," & Chr(34) & _
"therefore when you see the abomination of desolation standing in the Holy Place." & Chr(34) & _
"(let the reader understand) Matthew 24:15"

inktext.SelStart = 0
inktext.SelLength = Len(inktext.Text)
inktext.SelColor = vbBlue
inktext.SelFontSize = 18

firstpos = InStr(1, inktext.Text, Chr(34))
lastpos = InStr(firstpos + 1, inktext.Text, Chr(34))

inktext.SelStart = firstpos
inktext.SelLength = lastpos - firstpos - 1
inktext.SelColor = vbRed

inktext.SelLength = 0
End Sub
 
Upvote 0
Hi, the multiple text color is not possible using textbox but can do using additional control "Microsoft InkEdit Control" (see image)

View attachment 66316

The output would be as below.

View attachment 66314

Below is the macro used to display the text inside double quotes in RED font.
  1. The InkEdit control name is inktext.
  2. Chr(34) is used for double quotes.

VBA Code:
Private Sub UserForm_Activate()
Dim firstpos As Integer, lastpos As Integer

inktext.Text = "And Jesus Said to him," & Chr(34) & _
"therefore when you see the abomination of desolation standing in the Holy Place." & Chr(34) & _
"(let the reader understand) Matthew 24:15"

inktext.SelStart = 0
inktext.SelLength = Len(inktext.Text)
inktext.SelColor = vbBlue
inktext.SelFontSize = 18

firstpos = InStr(1, inktext.Text, Chr(34))
lastpos = InStr(firstpos + 1, inktext.Text, Chr(34))

inktext.SelStart = firstpos
inktext.SelLength = lastpos - firstpos - 1
inktext.SelColor = vbRed

inktext.SelLength = 0
End Sub
Saurabh - thanks - I've been at this for what seems like a thousand years. Will study and copy your
code shortly. If this works as you indicate, I would apply this of course to the entire New Testament
where all the words of Jesus within surrounding text are in red. About 160 location blocks.
cr
Hi, the multiple text color is not possible using textbox but can do using additional control "Microsoft InkEdit Control" (see image)

View attachment 66316

The output would be as below.

View attachment 66314

Below is the macro used to display the text inside double quotes in RED font.
  1. The InkEdit control name is inktext.
  2. Chr(34) is used for double quotes.

VBA Code:
Private Sub UserForm_Activate()
Dim firstpos As Integer, lastpos As Integer

inktext.Text = "And Jesus Said to him," & Chr(34) & _
"therefore when you see the abomination of desolation standing in the Holy Place." & Chr(34) & _
"(let the reader understand) Matthew 24:15"

inktext.SelStart = 0
inktext.SelLength = Len(inktext.Text)
inktext.SelColor = vbBlue
inktext.SelFontSize = 18

firstpos = InStr(1, inktext.Text, Chr(34))
lastpos = InStr(firstpos + 1, inktext.Text, Chr(34))

inktext.SelStart = firstpos
inktext.SelLength = lastpos - firstpos - 1
inktext.SelColor = vbRed

inktext.SelLength = 0
End Sub
Saurabh - thanks a mil. I'm going to study and copy this code into the UF's Activate event.
There are about 160 locations from Matt-John I want to do this for. So this defines a range.
If I can duplicate what you indicated above, the effort would be well worth it, if it has to be
done as one section of text at a time. However - my initial thought would be to write a FIND
code block that finds all the text within a defined range that begins with "Jesus said" and apply this code;

as I understand your code, the FIND code would have to know where to start applying red text and where to stop
applying red text, and that would be between quotes, [start red text here] "......"[stop red text here].

If this is able to be done with a FIND code correctly, it would complete the task very quickly.

Please let me know if I'm approaching this correctly.
Thanks again. Exciting to be able to do this at last! cr
 
Upvote 0
Hi Saurabh - not working. Selected control from Reference toolbox. Copied code in Userform Activate Event
Enlarged linkedit1 control and renamed to Inktext. See image(s). Why is it giving a compile error stating "Sub or function not defined"?

Thanks for your help.
cr
 

Attachments

  • COMPILE ERROR  WHEN RUNNING CODE.png
    COMPILE ERROR WHEN RUNNING CODE.png
    81.6 KB · Views: 6
  • USERFORM WITH INKEDIT CONTROL.  .png
    USERFORM WITH INKEDIT CONTROL. .png
    32 KB · Views: 6
Upvote 0
Title explains, ..
In relation to your title ..
Please see #14 of the Forum Rules
On looking back I see that you have been using all upper case in many of your thread titles over quite a period of time and I don't think the rule has been pointed out to you before. However, we would ask that you ensure your future thread titles conform to that rule.
Thanks.
 
Upvote 0
Did not intend to upset the apple cart. Will comply. Your experience in helping with some of the more
difficult tasks I've asked VBA to perform is greatly appreciated.
cr
 
Upvote 0
Hi Saurabh - not working. Selected control from Reference toolbox. Copied code in Userform Activate Event
Enlarged linkedit1 control and renamed to Inktext. See image(s). Why is it giving a compile error stating "Sub or function not defined"?

Thanks for your help.
cr
Please check the field name. if not correct, it will give compile error.
 
Upvote 0
Did not intend to upset the apple cart. Will comply.
Thanks. I did note your comment in another thread about your eyesight but all our replies are in normal size lower case so I presume you would just need to change your browser zoom setting if required anyway. :)
 
Upvote 0

Forum statistics

Threads
1,214,835
Messages
6,121,880
Members
449,057
Latest member
Moo4247

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top