Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Text box physical string length

Is there an easy way to get the length of a string (inches
or points) going into a text box before the AddTextbox
call?

I'm trying to center text at the centroid of closed
polylines - lots of them. Figuring character width as
~60% of the font size seems to be a hit or miss thing.
Maybe I could use Autosize and get the textbox length with
the AddTextbox call, but I'm finding it's slow. It would
likely be faster to figure it character by character once
the width vs character code is worked out.

Evan Weiner
Richland WA
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Text box physical string length

It is not a property that is provided by built in functions in Excel VBA.
You might be able to do something with the Windows API, but I have never
attempted it.

Can't you use the horizontalalignment property of the textframe. (assume
your shape has one).

--
Regards,
Tom Ogilvy

"Evan" wrote in message
...
Is there an easy way to get the length of a string (inches
or points) going into a text box before the AddTextbox
call?

I'm trying to center text at the centroid of closed
polylines - lots of them. Figuring character width as
~60% of the font size seems to be a hit or miss thing.
Maybe I could use Autosize and get the textbox length with
the AddTextbox call, but I'm finding it's slow. It would
likely be faster to figure it character by character once
the width vs character code is worked out.

Evan Weiner
Richland WA



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Text box physical string length

Hi Evan

Inches would depend on screen resolution, zoom, ... Here's a solution for
the text width in pixels. Add a Userform1 with a Label1 on it in your
workbook:

Function MyTextWidth(sText As String, _
sFont As String, _
LFontSize As Long) As Long
With UserForm1.Label1
..AutoSize = False
..Font.Name = sFont
..Font.Size = LFontSize
..Width = 5000
..Caption = sText
DoEvents
..AutoSize = True
MyTextWidth = .Width
End With
Unload UserForm1
End Function

Sub TEST()
MsgBox MyTextWidth("Harald rules", _
"Times New Roman", 10)
MsgBox MyTextWidth("No, it's really Rumsfeldt. Just kidding.", _
"Times New Roman", 10)
End Sub

HTH. Best wishes Harald

"Evan" skrev i melding
...
Is there an easy way to get the length of a string (inches
or points) going into a text box before the AddTextbox
call?

I'm trying to center text at the centroid of closed
polylines - lots of them. Figuring character width as
~60% of the font size seems to be a hit or miss thing.
Maybe I could use Autosize and get the textbox length with
the AddTextbox call, but I'm finding it's slow. It would
likely be faster to figure it character by character once
the width vs character code is worked out.

Evan Weiner
Richland WA



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fixed length string of text MWysack Excel Discussion (Misc queries) 7 March 21st 13 12:05 AM
length of text string goes beyond cells are not visible Tom Excel Discussion (Misc queries) 3 November 2nd 05 11:23 PM
Limiting physical length of text in a text box control XL2Know Excel Discussion (Misc queries) 1 October 6th 05 01:55 PM
want to remove all text characters equal to one character in length from text string [email protected] Excel Worksheet Functions 1 April 18th 05 09:56 PM
want to remove all text characters equal to one character in length from text string [email protected] Excel Worksheet Functions 1 April 18th 05 12:25 AM


All times are GMT +1. The time now is 07:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"