PDA

View Full Version : Need help with changing a font size



Chukesgirl
01-05-2006, 06:14 PM
Hi All

I am a diehard Wordperfect user trying to adjust to Word and I am really struggling with Word VBA, but I keep trudging along with help from forums like these, so thanks in advance for any help you can give.

I have created a very nice little template with a custom user box. It has 3 option buttons with some coding and it works just fine, only now I want the text of one of the options (optconf) to be in a 20 pt. bolded font. Can someone help me with this? :help Here is the part of the code I need help with:


If frmlegal.optpub.Value = True Then
ActiveDocument.Bookmarks("designation").Range.Text = "PUBLIC MATTER - DESIGNATED FOR PUBLICATION"
End If
If frmlegal.optnopub.Value = True Then
ActiveDocument.Bookmarks("designation").Range.Text = "PUBLIC MATTER - NOT DESIGNATED FOR PUBLICATION"
End If
If frmlegal.optconf.Value = True Then
ActiveDocument.Bookmarks("designation").Range.Text = "CONFIDENTIAL"
End If

Application.ScreenUpdating = True
Unload Me
End Sub

matthewspatrick
01-05-2006, 07:02 PM
frmlegal.optconf.Font.Bold = True
frmlegal.optconf.Font.Size = 20

Chukesgirl
01-06-2006, 11:33 AM
Hi Matthewspatrick

I put your code in as shown below and it didn't work. I also put your code in it's own If statement and it still didn't work. Should I have put it somewhere else?


If frmlegal.optconf.Value = True Then

frmlegal.optconf.Font.Bold = True
frmlegal.optconf.Font.Size = 20
ActiveDocument.Bookmarks("designation").Range.Text = "CONFIDENTIAL"
End If

fumei
01-06-2006, 11:47 AM
Not sure what you are trying to do.

You ARE talking about a UserForm, yes? These are option button on a UserForm, NOT option buttons in the document? Correct?

WHY would you want to change the bold/size of the option control on the UserForm if it is true?

WHAT is firing the code? I am trying to get the connection between determining the value and putting the text into the bookmark. As far as I can see once the value is determined, and the text goes into the bookmark, your UserForm is unloaded...so..uh, why are you making the control bold and sized?

Private Sub CommandButton2_Click()
OptionButton2.Font.Size = 20
OptionButton2.Font.Bold = True
End Sub
on a UserForm will change the OptionButton control when CommanButton2 is clicked. This works regardless of whether the control is in a frame, or not. In other words, if this is firing IN the form, the form object is not required to identify it.

Chukesgirl
01-06-2006, 12:10 PM
Hi Gerry

You are correct about the Userform. (I don't even know how to put an option button in a document yet)

Let me see if I can simplify what I am trying to do here.

When the user box is displayed when the template is opened, there are 3 radio buttons designating what kind of document this will be.
1. Public
2. Non Public
3. Confidential
The user selects one and it goes to the "designation" book mark and types in the text, Public, Non Public or Confidential. We really want the word "Confidential" to stand out in the document, so we want a 20 pt. bolded font to appear when the user selects that option.

Now the code that I have put in so far works (see above), but I just don't know how to make the word "Confidential" stand out.

fumei
01-06-2006, 02:21 PM
Uh....then don't you want the inserted TEXT to be bold and size 20...not the option button. Again, the option button is on the form...when it finishes, the form is unloaded. So why on earth try and make the form control (the option button) do anything.

As you state yourself you want it stand out IN THE DOCUMENT. So make it stand out in the document...not the userform. Make sense?

Therefore you want to action the text - in the document. It has nothing whatsoever to do with the userform.

So:
With ActiveDocument.Bookmarks("designation").Range
.Font.Size = 20
.Font.Bold = True
.Text = "CONFIDENTIAL"
End With

Now you may have a problem if you are doing any repeated insertion into the bookmark. Depending on your version of Word, inserting text "into" a bookmark via .Range.Text, does NOT resize the bookmark to include that text. It inserts it afterwards.

Bizarre, but true. It can also delete the bookmark itself. There are reasons for this because of the way the object model works.

If this is a problem for you post back, because there IS a solution.

Chukesgirl
01-06-2006, 03:06 PM
Yes, yes, yes! you understand ! It's the text I want to control, not the option. As I said, I am new to Word VBA coding and I was probably not stating myself clearly. I will try your suggestion and see what happens. Thanks.

fumei
01-08-2006, 07:23 AM
Oh you stated yourself clearly...

only now I want the text of one of the options (optconf) to be in a 20 pt. bolded font
you just stated yourself incorrectly.

Essentially you wanted to know how to make bookmark text bold and size 20. The fact that text came from an option button choice is in this case, frankly, irrelevant.

Hopefully it will work for you. As I said, if you have a problem with repeating your inserted text, post back.

Good luck!

PS - welcome to the wonderful strange world of Word.