Results 1 to 4 of 4

Thread: font size based on character count within a text form field field...

  1. #1

    font size based on character count within a text form field field...

    how can I reduce the font size of a text form field based on the number of characters?


    The code should make this form field (the one that says "Customer Name") go from this:
    Capture187.JPG

    to look like this:
    Capture189.JPG


    I use this code in excel to accomplish the same thing in a userform textbox.. but cant figure out how to do this same thing in word:


        With Me.txtTrainingName
             If .TextLength Mod 4 = 0 Then
                 Select Case .TextLength
                     Case Is < 74
                         .Font.Size = 14
                     Case 74 To 80
                         .Font.Size = 13
                     Case 80 To 90
                         .Font.Size = 12
                     Case Is > 90
                         .Font.Size = 11
    '
                 End Select
             End If
        End With

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,132
    Location
    Why not just make the font the same size no matter the length of the customer name?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    Thank you for replying Aussiebear.
    Its because I would like to keep the font size as large as possible (within reason...)
    Most entries into most fields (btw I plan to use the code for all the fields on this form) will be short enough not to exceed the default font size. Only a few will be of a long enough entry that would require a smaller font size that will allow the entry to fit within the confines of particular cell where text form field is. I wouldn't want to make all the fields smaller than I need to just to allow the occasional long entry to properly fit.

    (this is a protected form btw and the user does not have control to make formatting changes.) Thanks again.

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,359
    Location
    I have to wonder why (in 2024) you are using formfields instead of content controls in your form. Regardless:

    Sub FFOnExit()
    Dim oFld As Word.FormField
      If Selection.FormFields.Count = 1 Then
        Set oFld = ActiveDocument.FormFields(Selection.FormFields(1).Name)
      ElseIf Selection.FormFields.Count = 0 And Selection.Bookmarks.Count > 0 Then
        Set oFld = ActiveDocument.FormFields(Selection.Bookmarks(Selection.Bookmarks.Count).Name)
      End If
      With oFld
        Select Case Len(.Result)
           Case Is < 74
             .Range.Font.Size = 14
           Case 74 To 80
             .Range.Font.Size = 13
           Case 80 To 90
             .Range.Font.Size = 12
           Case Is > 90
             .Range.Font.Size = 11
        End Select
      End With
    lbl_Exit:
      Exit Sub
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

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