Results 1 to 8 of 8
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    New York
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Fonts and Objects in Forms (VBA/Word)

    I've been struggling with the peculiarity of maintaining cross platform versions of an add-in. The most annoying problem with programming for both WordX:Mac and Wordxp/2003 is the different default font used in Forms (Tahoma in Windows and Geneva in Mac) -- and the resulting incompatibility of forms designed in one OS and then opened in the other.

    Then it occured to me: why not redo all the forms using a font I know is common to both OSes. Courier New Bold.

    Which might solve a lot of problems.

    So here's the question. Is there a way to programmatically loop through all the objects in a VBA form and change the applied font? I can't think of anyway to automate this. Perhaps the only method short of brute force is to export to a FRM file and edit that text file and re-import.

    Any thoughts apprciated.

    p.s. I don't want to loop at runtime and change the font dynamically each time the form is displayed. That would not solve the problem of form design and spacing. What I want is to change ALL hard coded references to Tahoma to hard coded references to Courier New Bold. Then do the layout and spacing for each form.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Fonts and Objects in Forms (VBA/Word)

    In Word for Windows, you can do something like this, I have no idea whether it is possible in Word for the Mac:

    - Set a refererence to the Microsoft Visual Basic for Applications Extensibility 5.3 library in Tools | References...
    - Run the following macro:

    Sub ChangeFont()
    Dim vbc As VBComponent
    Dim ctl As Control
    On Error GoTo ErrHandler

    For Each vbc In ActiveDocument.VBProject.VBComponents
    If vbc.Type = vbext_ct_MSForm Then
    For Each ctl In vbc.Designer.Controls
    ctl.Font.Name = "Courier New"
    ctl.Font.Bold = True
    NextOne:
    Next ctl
    End If
    Next vbc

    ExitHandler:
    Set ctl = Nothing
    Set vbc = Nothing
    Exit Sub

    ErrHandler:
    If Err = 438 Then ' property does not exist
    Resume NextOne
    Else
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End If
    End Sub

    - Check whether the result is OK, then save the document or template.

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Fonts and Objects in Forms (VBA/Word)

    > p.s. I don't want to loop at runtime a

    I change my fonts, captions, pointer and colors at run-time - onthe fly at the user request.
    I've struggled with being able to make a change, for sthe sake of stndards, at compile time, but have just about given up.
    You may have some luck with this <post:=472,001>post 472,001</post:>.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Fonts and Objects in Forms (VBA/Word)

    Within the Designer object, you can manipulate controls much the same way as in runtime. If you want to add or manipulate event procedures, you must use code to create code. This is quite possible, but confusing because of the layers you're dealing with. Chip Pearson has a web page on working with code to modify code. It's geared towards Excel, but the general principles apply in Word too: Programming To The VBE.

    You can check the type of a control using the TypeName function:

    For Each ctl In vbc.Designer.Controls
    Select Case TypeName(ctl)
    Case "TextBox"
    ...
    Case "ComboBox"
    ...
    Case "Label"
    ...
    Case ...
    ...
    End Select
    Next ctl

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Fonts and Objects in Forms (VBA/Word)

    > that is usfule
    I wish I'd seen that coming (grin!)

    Not that I'm aware of.
    I had a project last month where I wanted to build controls (Listboxes mainly) to the number specified by the user. I spent the best part of a day hunting for a solution that worked for me, but couldn't find anything.
    The project ("MyINI") is to take any INI file and build a set of GUI forms that facilitate editing of the INI file. Hence, one form per section in the INI file, CheckBoxes for boolean, listboxes for lists, and textboxes for text and everything else. I wanted a means of providing a cheap and nasty GUI interface for an existing AP that had generated an INI file, so i wanted to create a GUI form by program code and save that form with the application.

  6. #6
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    New York
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Fonts and Objects in Forms (VBA/Word)

    For my purposes, the code HansV posted is a great start and points me in a direction.

    It does work on Word Mac. And the resulting modified forms -- to use a common font -- definitely seems to make the cross platform visuals more compatible.

    Now I need too loop thorugh each control and do a series of changes based on type of control.

    Is there a resource other than the helpfile (on the web) that is useful in working with the Designer object?

  7. #7
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    New York
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Fonts and Objects in Forms (VBA/Word)

    Thanks for the help, Hans and Chris.

    The code you posted makes it trivial to modify forms in a project. And it then the forms are acceptable on both platforms.

    Regards,

    Guy

  8. #8
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Fonts and Objects in Forms (VBA/Word)

    I have an Excel file with some code that:

    - Creates a worksheet with the properties of all controls on all userforms in the active workbook
    - Enables to pull the data from that worksheet that recreates userforms based on that worksheet

    With this you can "export" a current form, edit all properties in the worksheet and create a new userform based on the properties in the worksheet.

    Let me know of you want the code.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

Posting Permissions

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