PDA

View Full Version : [SOLVED] Change Font of UserForm1



wnazzaro
06-20-2005, 01:57 PM
Seems simple enough, yet I am missing something. I have no problem setting the Font for labels and text boxes. Yet to programmatically set the Font is outside my ken. Not really important, as the only thing I can't set is the Font of the Caption, but once the Font is set for the entire form, I wouldn't have to set the Font for each element thereafter.

.Properties("Font").Object will return the Font name of the form but
.Properties("Font").Object = "Verdana" returns the error message:


Compile Error:

Method or data member not found

Thanks for any help.
Bill

Jacob Hilderbrand
06-20-2005, 02:10 PM
Something like this should work for you.


Me.Font.Name = "Verdana"

wnazzaro
06-21-2005, 08:20 AM
Something like this should work for you.


Me.Font.Name = "Verdana"

Nope. I'm creating a form through a sub called by another form. I tried putting the code in Private Sub UserForm1_Initialize, is there somewhere else I should put it?

Bob Phillips
06-21-2005, 08:30 AM
Nope. I'm creating a form through a sub called by another form. I tried putting the code in Private Sub UserForm1_Initialize, is there somewhere else I should put it?

Are you using Designer? That is read-only according to the object browser.

Jacob Hilderbrand
06-21-2005, 09:14 AM
Can you attach the file you are working with so we can have a closer look?

wnazzaro
06-21-2005, 10:34 AM
This should be enough code to get an idea of what I'm trying to do. Again, this really isn't important, but I like to learn. Just add the code below into a Subprocedure.


Dim EditForm As VBComponent
Set EditForm = ThisWorkbook.VBProject.VBComponents.Add(vbext_ct_MSForm)
EditForm.Properties("Font").Object = "Verdana"

You can use Designer to change the font name of objects on the form, just not for the form.
So this works for labels


For i = 1 To 7
With EditForm.Designer.Controls.Add( _
"Forms.Label.1", "lbl" + CStr(i), True)
.Height = 12
.Font.Name = "Verdana"
End With
Next

but not for the entire form.

Bob Phillips
06-21-2005, 11:14 AM
This should be enough code to get an idea of what I'm trying to do. Again, this really isn't important, but I like to learn. Just add the code below into a Subprocedure.

I think that the problem is your object exposes a limited set of properties, of which Font is not one. Thus to get at the form's font property, I think you have to add it, and then access it there.


Dim EditForm As VBComponent
Dim EditForm2 As Object
Set EditForm = ThisWorkbook.VBProject.VBComponents.Add(vbext_ct_MSForm)
For i = 1 To 7
With EditForm.Designer.Controls.Add( _
"Forms.Label.1", "lbl" + CStr(i), True)
.Height = 12
.Font.Name = "Verdana"
End With
Next
Set EditForm2 = UserForms.Add(EditForm.Name)
EditForm2.Font.Name = "Verdana"

wnazzaro
06-21-2005, 01:18 PM
Well, it doesn't fail, but it doesn't work either. I now don't think it is possible to actually change the Font of a Form header. Even if you change it in the IDE, the Font never changes from Tahoma.

Thanks for trying, this one was bugging me. Unless someone can post something to the contrary, I don't think this is possible.

Bill

MOS MASTER
06-21-2005, 01:47 PM
Hi Bill, :yes

AFAIK the Font of the Title bar (Caption UserForm) follows the Windows theme you can set in display properties. (Rightclick | Desktop | Properties)

But of course this wil be done for all title bars in Windows!

Perhaps its possible to do it with API's but haven't tried it so I wouldn't know.

Good luck. :whistle:

wnazzaro
06-22-2005, 11:35 AM
Though if you could change the setting, I believe you wouldn't need to set the font for labels, text boxes, etc. It would save some lines of code.

MOS MASTER
06-22-2005, 11:41 AM
Though if you could change the setting, I believe you wouldn't need to set the font for labels, text boxes, etc. It would save some lines of code.
Fonts for labels textboxes and stuff are not addressed by the windows theme!

So no that won't work. This wouldn't be smart of MS because that would limit people in formatting there UserForms.

But Titlebar is for sure part of the Windows theme...
So no..sorry don't trow your code away yet..:rotlaugh:

Bob Phillips
06-22-2005, 01:54 PM
Fonts for labels textboxes and stuff are not addressed by the windows theme!

Joost,

He is trying to set the form font, which would then be inherited by any controls.

Just as if you set the form font in designer, the controls then added assume that font.

wnazzaro
06-22-2005, 01:55 PM
Fonts for labels textboxes and stuff are not addressed by the windows theme!



Sorry, there may be a language issue here, that's not what I meant.
If you set the Font.Name at the Form level, that Font will be used for each label, text box, etc. You can code the Font.Name for each element, but it would save one line of code for each element if you could set the Font at the Form level.

MOS MASTER
06-22-2005, 02:09 PM
Joost,

He is trying to set the form font, which would then be inherited by any controls.

Just as if you set the form font in designre, the controls then added assume that font.
Hi Bob, :yes

Ah Ok perhaps I was offset by:

Not really important, as the only thing I can't set is the Font of the Caption

That made me believe he wanted to change that...:whistle:

MOS MASTER
06-22-2005, 02:10 PM
Sorry, there may be a language issue here, that's not what I meant.
If you set the Font.Name at the Form level, that Font will be used for each label, text box, etc. You can code the Font.Name for each element, but it would save one line of code for each element if you could set the Font at the Form level.
Hi, :yes

Sorry no language issue here...just misinterpretation from my side...:whistle:

wnazzaro
06-22-2005, 02:14 PM
That made me believe he wanted to change that...:whistle:

I did, until you explained where that is set. There were two things I wanted to do, set the Font of the Title Bar (which, I now know is set by Windows) and set the Font for the controls added to the Form.

Thanks for the information and the help,
Bill

MOS MASTER
06-22-2005, 02:20 PM
Hi Bill, :yes

You're welcome and I'm sorry for the confusing part! :*)