Adjusting textbox font size based on string length

mzza

Board Regular
Joined
Nov 8, 2006
Messages
55
Hi there,

as per the thread title, I am trying to adjust the font size of the text in an embedded textbox in the "Quote" sheet, using the following code:

Code:
Set wordobj2 = Sheets("Quote").OLEObjects(2)
wordobj2.Object.Text = Countries_String

    Select Case CountryCharLength
        Case 1 - 1400
            wordobj2.Object.Font.Size = 12
        Case 1401 - 2000
            wordobj2.Object.Font.Size = 11
        Case 2001 - 2500
            wordobj2.Object.Font.Size = 10
        Case 2501 - 3000
            wordobj2.Object.Font.Size = 9
        Case 3001 - 3500
            wordobj2.Object.Font.Size = 8
        Case 3501 - 4000
            wordobj2.Object.Font.Size = 7
        Case Is > 4000
            wordobj2.Object.Font.Size = 6
     End Select

"CountryCharLength" is an integer based on the character length of the string I'm passing into the textbox, and is evaluating correctly. Why does my Select Case statement not change the font size? Like, ever? :s

On a related note - can I refer to my textbox by the name I've given it ("TxtBoxCountries") in its Properties? What's the correct syntax for that?

TIA
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
try using...

Case 1 To 1400

etc
 
Upvote 0
I believe this is what they call a 'schoolboy error'... >.<

Thank you diddi, much appreciated
 
Upvote 0
easy to do. btw if your font is proportional, you may get odd results. i seem to remember theire is a Width() of a string which gives actual pixel width.
 
Upvote 0

Forum statistics

Threads
1,224,514
Messages
6,179,220
Members
452,895
Latest member
BILLING GUY

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top