Changing the Text Form Feilds font color

J

Jeffery B Paarsa

Hello,

Private Sub CommandButton1_Click()
With ActiveDocument
.Unprotect
.Range.Font.Color = wdColorRed
.Bookmarks("PLName").Range _
.InsertBefore TextBox1
.Bookmarks("PFName").Range _
.InsertBefore TextBox2
.Bookmarks("PIName").Range _
.InsertBefore TextBox3
.Protect wdAllowOnlyFormFields
End With
UserForm1.Hide

End Sub

The above code will be executed after a UserForm was displayed after double
clicking on a Word Template "xxx.dot". I would like to be able to change
just the font size & color of the text at the time of inserting the captured
fields into the Bookmarks. I used .Range.Font.Color = wdColorRed but this
will change the font color of the entire document not just the inserted
Bookmarks fields.

Anyone has any suggestion? How about changing the Font size of inserted
characters too?

Regards
 
D

Dave Lett

Hi Jeff,

You need to apply the font color to the correct range. Have a look at the
following:

Dim oRng As Range
With ActiveDocument
Set oRng = .Bookmarks("Test1").Range
With oRng
.Text = "myTest"
.Font.Color = wdColorRed
End With
Set oRng = .Bookmarks("Test2").Range
With oRng
.Text = "second test"
.Font.Color = wdColorRed
End With
End With


Also, it sounds like you're using placeholder bookmarks, which makes it a
little more challenging. For a good discussion of bookmark types see the
article "Working with Bookmarks in VBA" at
http://word.mvps.org/FAQs/General/index.htm.

HTH,
Dave
 
G

Greg Maxey

Jeff,

I don't have a Userform to code with, but basically you just declare a
range. Set it to the bookmark range, put your textbox text in the
range (which will wipe the bookmark) and reassign the bookmark name to
the range. Here is ane example.

Private Sub Test()
Dim oRng As Word.Range
With ActiveDocument
.Unprotect
Set oRng = .Bookmarks("PLName").Range
With oRng
.Text = "Your TextBox1 Text"
.Font.Color = wdColorRed
.Font.Size = 18
End With
.Bookmarks.Add "PLName", oRng
Set oRng = .Bookmarks("PLAddress").Range
With oRng
.Text = "Your TextBox2 Text"
.Font.Color = wdColorGreen
.Font.Size = 6
End With
.Bookmarks.Add "PLAddress", oRng
.Protect wdAllowOnlyFormFields, True
End With
End Sub
 
J

Jeffery B Paarsa

Thanks for your help... Your response was as good as Greg's but his was also
showing how to change the font size too.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top