Problem with Word Forms text change

madchemist

Board Regular
Joined
Jul 10, 2006
Messages
198
I am trying to write a macro to change the text color in a forms textbox. I need the textbox to have blue instructions in it, and then turn into black text after the user enters information.

I have quite a bit of experience working with excel macros, but feel stupid that I cannot figure this out. I put this macro in the textboxes properties upon exit, but it doesnt change the text color.

Any ideas? I would prefer to leave it generic to the textbox it is on instead of specifically calling out a textbox to change. I would like to use this in a few areas....

thanks!

Code:
Sub TextChange()

    ActiveDocument.Unprotect 
    Selection.Font.ColorIndex = 1
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, 
    
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
OK, i got it to work....kind of. This is what I ended up with.

Code:
Sub TextColor()
    ActiveDocument.Unprotect Password:="test"
    If Selection.Font.Color = wdColorBlue Then
    Selection.Font.Color = wdColorBlack
    End If
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="test"
End Sub

This works fine when a user tabs into the cell. It changes it black as soon as they tab in. However, if they click on the cell it only changes the word they clicked on, not the whole textbox.

Does anyone know how to select the whole textbox?

Thanks!
 
Upvote 0

Forum statistics

Threads
1,225,408
Messages
6,184,824
Members
453,262
Latest member
tifra

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