PC Review


Reply
Thread Tools Rate Thread

Compute length of a string in points depending on current font

 
 
poptcat@yahoo.com
Guest
Posts: n/a
 
      1st Feb 2008
Hi.
I have to compute the length of a string in order to achieve the best
fitting inside a cell.
So given a range of merged cells or a single cell I want to resize the
range to get the whole text visible. Without using wrap or shrink.
I can't get a good aproximation for all fonts. For example, using x as
the average char, I can't write Verdana.
No need to mention I didn't find any resource on this matter.
Does anyone know how to solve it?
Gabi
 
Reply With Quote
 
 
 
 
Helmut Weber
Guest
Posts: n/a
 
      1st Feb 2008
Hi Gabi,

see:

http://groups.google.de/group/micros...f88076e188ebf7

Tinyurl:

http://tinyurl.com/2he88q

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
Reply With Quote
 
Ron Rosenfeld
Guest
Posts: n/a
 
      1st Feb 2008
On Fri, 1 Feb 2008 03:40:53 -0800 (PST), (E-Mail Removed) wrote:

>Hi.
>I have to compute the length of a string in order to achieve the best
>fitting inside a cell.
>So given a range of merged cells or a single cell I want to resize the
>range to get the whole text visible. Without using wrap or shrink.
>I can't get a good aproximation for all fonts. For example, using x as
>the average char, I can't write Verdana.
>No need to mention I didn't find any resource on this matter.
>Does anyone know how to solve it?
>Gabi


You could use the AutoFit Method.
--ron
 
Reply With Quote
 
poptcat@yahoo.com
Guest
Posts: n/a
 
      1st Feb 2008
Thanks for your response. I need a method for all Excel versions and
for all font types. I tried Autofit too.
I found something with API functions
http://www.mrexcel.com/archive2/17500/19912.htm
I'll try this.
Thanks again
 
Reply With Quote
 
Dave D-C
Guest
Posts: n/a
 
      1st Feb 2008
Helmut,
Ludo said "Thanks!" in that thread, but I didn't
get much out of it. Is that the right thread?

Gabi,
How about putting your text into an unused column,
e.g. cells(1,9), and then:
Sub Sub1()
Dim zWidth!
Columns(9).ColumnWidth = 1
Columns(9).AutoFit
zWidth = Columns(9).Width
MsgBox zWidth
End Sub
Dave D-C ------- please top-post in this group

Helmut Weber <(E-Mail Removed)> wrote:
>Hi Gabi,
>see:
>http://groups.google.de/group/micros...f88076e188ebf7
>Tinyurl:
>http://tinyurl.com/2he88q


(E-Mail Removed) wrote:
>Hi.
>I have to compute the length of a string in order to achieve the best
>fitting inside a cell.
>So given a range of merged cells or a single cell I want to resize the
>range to get the whole text visible. Without using wrap or shrink.
>I can't get a good aproximation for all fonts. For example, using x as
>the average char, I can't write Verdana.
>No need to mention I didn't find any resource on this matter.
>Does anyone know how to solve it?
>Gabi



 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      1st Feb 2008
Unless you are sure there are no mixed font formats stick with the autofit
method (ensure there's only one cell with contents in the column you will
autofit). Note respective versions have slightly different 'padding' width.
There's also a slightly more accurate way to get the width of text by using
a textbox but quite a lot more work.

Regards,
Peter T

<(E-Mail Removed)> wrote in message
news:d4f1aaf6-6425-4b08-9296-(E-Mail Removed)...
> Thanks for your response. I need a method for all Excel versions and
> for all font types. I tried Autofit too.
> I found something with API functions
> http://www.mrexcel.com/archive2/17500/19912.htm
> I'll try this.
> Thanks again


 
Reply With Quote
 
Helmut Weber
Guest
Posts: n/a
 
      1st Feb 2008
Sorry,

>Helmut,
>Ludo said "Thanks!" in that thread, but I didn't
>get much out of it. Is that the right thread?


that was an answer for Word-users,
who like to find out whether text fits
into word table cells.
--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
length of a string using inches to points help! chrislooney0@googlemail.com Microsoft Excel Programming 0 11th Dec 2008 11:05 AM
len() function returning byte length instead of string length Demosthenes Microsoft VB .NET 5 23rd Jan 2008 06:55 PM
can't get length of symbol string in points =?Utf-8?B?SGlwZXJpWA==?= Microsoft Dot NET 1 11th Oct 2007 10:37 AM
what if problem to compute cost depending on time aj9409 Microsoft Excel Misc 1 26th Jan 2006 02:53 PM
Attention: Webforms setting the with of a textbox, depending of the len of the string and the font ton Microsoft VB .NET 3 10th Feb 2004 06:19 PM


Features
 

Advertising
 

Newsgroups
 


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