Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-15-2021, 05:47 AM
knpaddac knpaddac is offline Select and change font size of words by number of characters Windows 10 Select and change font size of words by number of characters Office 2016
Novice
Select and change font size of words by number of characters
 
Join Date: Jan 2018
Posts: 13
knpaddac is on a distinguished road
Default Select and change font size of words by number of characters

Is there some way to create a macro that would size all words in a document based on the number of letters, numbers, non-spaces in the string?



I have to make adhesive labels for book spines and typically anything with 9 or more characters needs to be sized to 10 points to fit on the labels.

Last edited by Charles Kenyon; 03-15-2021 at 08:26 AM. Reason: Change highlight to select
Reply With Quote
  #2  
Old 03-15-2021, 08:29 AM
Charles Kenyon Charles Kenyon is offline Select and change font size of words by number of characters Windows 10 Select and change font size of words by number of characters Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,138
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

[Moderator's note: I edited your post to use the word "select" instead of "highlight" since I am confident that is what you meant. I also specified that what you want to do is size rather than just select the text. If I was mistaken, please change it back. Feel free to lambast me.]

Yes. It is possible. Anyone trying to help you with this is going to want to know how you are preparing the labels.

Mail Merge? (This is most efficient.)

How many labels at a time?

Can you provide a sample document? How to attach a screenshot or file in this forum. (Word file, not screenshot)

How familiar are you with writing macros in the vba editor?
Reply With Quote
  #3  
Old 03-15-2021, 09:24 AM
knpaddac knpaddac is offline Select and change font size of words by number of characters Windows 10 Select and change font size of words by number of characters Office 2016
Novice
Select and change font size of words by number of characters
 
Join Date: Jan 2018
Posts: 13
knpaddac is on a distinguished road
Default

To clarify, this if for books in a library, so the process goes something like this:

-the books are cataloged in the ILS
-in the ILS I pull lists of the books to be labeled and then the call numbers are exported to a csv file in Excel. Ideally i do 100 at a time, as that is how many are on each sheet (8.5x11) but that is rarely the case, it varies...40, 50, 72, etc.
-in Excel, I manually shift the cells into columns of 10 each and then copy/paste that onto the dummy template Word file from the company that produces the labels. These are .75x1 inch labels, 100 per sheet.
-from there I highlight all the labels and use a macro I recorded which replaces all spaces with linebreaks (or maybe paragraphs is the correct term), changes the font to Arial rounded MT Bold, and sets the size to 11pt.
-THIS IS THE PART I AM LOOKING TO CUTDOWN ON: At this point I have to manually go through and modify any instances where the names or other info is too long to fit on a line, downsizing such lines to 10pt, 9pt, or whatever. Typically a string of 8 letters seems to fit, but more than that tends to throw off the formatting. So, if there were some way to automatically search for strings of 9 or more and downsize them to 10pt, I think that would be beneficial.


I have attached a couple of documents, the '.75x1' is the mostly blank template I paste the info into and the other is a recent sheet as it ended up being printed.



Quote:
Originally Posted by Charles Kenyon View Post
[Moderator's note: I edited your post to use the word "select" instead of "highlight" since I am confident that is what you meant. I also specified that what you want to do is size rather than just select the text. If I was mistaken, please change it back. Feel free to lambast me.]

Yes. It is possible. Anyone trying to help you with this is going to want to know how you are preparing the labels.

Mail Merge? (This is most efficient.)

How many labels at a time?

Can you provide a sample document? How to attach a screenshot or file in this forum. (Word file, not screenshot)

How familiar are you with writing macros in the vba editor?
Attached Files
File Type: docx .75x1.docx (12.4 KB, 5 views)
File Type: docx 2021_03_11_labels.docx (13.9 KB, 6 views)
Reply With Quote
  #4  
Old 03-15-2021, 03:00 PM
macropod's Avatar
macropod macropod is offline Select and change font size of words by number of characters Windows 10 Select and change font size of words by number of characters Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Such labels are usually generated via a mailmerge, in which case, see: https://www.msofficeforums.com/125792-post2.html

Otherwise, try the following macro:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Tbl As Table, Cll As Cell, Par As Paragraph, sCllWdth As Single, sParWdth As Single
With ActiveDocument
  For Each Tbl In .Tables
    With Tbl
      With .Cell(1, 1)
        sCllWdth = .Width - .LeftPadding - .RightPadding
      End With
      For Each Cll In .Range.Cells
        With Cll
          .WordWrap = False
          If Len(.Range) > 2 Then
            For Each Par In .Range.Paragraphs
              With Par.Range
                sParWdth = .Characters.Last.Previous.Information(wdHorizontalPositionRelativeToPage)
                sParWdth = sParWdth - .Characters.First.Information(wdHorizontalPositionRelativeToPage)
                If sParWdth + Par.LeftIndent > sCllWdth Then .FitTextWidth = sCllWdth - Par.LeftIndent
                If .Characters.Last.Previous.Information(wdVerticalPositionRelativeToPage) <> _
                  .Characters.First.Information(wdVerticalPositionRelativeToPage) Then
                  .FitTextWidth = sCllWdth - Par.LeftIndent
                End If
              End With
            Next
          End If
        End With
      Next
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Select and change font size of words by number of characters VBA - Word how to globally change the font and font size in footnotes thomasoj Word VBA 3 01-15-2020 06:26 AM
VBA - change font and font size for Word footnote thomasoj Word VBA 1 01-15-2020 02:37 AM
Select and change font size of words by number of characters Looping Macro to Change Font, Font Size, and Give Heading 1 WH7262 Word VBA 1 08-26-2014 03:46 PM
Select and change font size of words by number of characters how change size font to inches size kkepo Word 4 08-28-2012 08:53 PM
Select and change font size of words by number of characters Highlight the first X number of characters 14spar15 Word 1 11-13-2011 11:17 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:04 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft