Consulting

Results 1 to 17 of 17

Thread: Change Font of UserForm1

  1. #1
    VBAX Regular
    Joined
    Feb 2005
    Posts
    82
    Location

    Change Font of UserForm1

    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

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Something like this should work for you.

    Me.Font.Name = "Verdana"

  3. #3
    VBAX Regular
    Joined
    Feb 2005
    Posts
    82
    Location
    Quote Originally Posted by DRJ
    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?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by wnazzaro
    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.

  5. #5
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Can you attach the file you are working with so we can have a closer look?

  6. #6
    VBAX Regular
    Joined
    Feb 2005
    Posts
    82
    Location
    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.

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by wnazzaro
    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"

  8. #8
    VBAX Regular
    Joined
    Feb 2005
    Posts
    82
    Location
    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

  9. #9
    Administrator
    VP-Knowledge Base VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Bill,

    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.
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  10. #10
    VBAX Regular
    Joined
    Feb 2005
    Posts
    82
    Location
    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.

  11. #11
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by wnazzaro
    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..
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  12. #12
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by MOS MASTER
    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.

  13. #13
    VBAX Regular
    Joined
    Feb 2005
    Posts
    82
    Location
    Quote Originally Posted by MOS MASTER
    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.

  14. #14
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by xld
    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,

    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...
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  15. #15
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by wnazzaro
    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,

    Sorry no language issue here...just misinterpretation from my side...
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  16. #16
    VBAX Regular
    Joined
    Feb 2005
    Posts
    82
    Location
    Quote Originally Posted by MOS MASTER
    That made me believe he wanted to change that...
    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

  17. #17
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Bill,

    You're welcome and I'm sorry for the confusing part!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •