PC Review


Reply
Thread Tools Rate Thread

Calculate string width in inches nzDec01

 
 
Neal Zimm
Guest
Posts: n/a
 
      1st Dec 2008
HI all,
The worksheets in my app must be printed on paper about 7 inches wide in a
font size of at least 18 or 20 to be read in very dim lighting. Column
widths are fixed.

If a macro generated text string does not 'fit' into the designated cells
in 1 row, I use more than 1 row to hold the text after spliting it into
'words'.

I'm trying to AVOID building a function to return the width of a character
string in inches, for a few font sizes and 1 to 3 font names.

.Shrinktofit on its own doesn't seem to help.

1. I can't find a way to test, If OneCell.Shrinktofit = true then Did
Excel actually shrink the cell contents ? This would help.

2. Is a call available to MSword that returns the width in inches of a
string, where its input is the font name and size of the characters? (It's
gotta be there, but is it available to mortals? I've also posted this on the
Word bulletin board.)

3. What might other 'stuff' be that I might be able to use?

Thanks.
--
Neal Z
 
Reply With Quote
 
 
 
 
Jim Thomlinson
Guest
Posts: n/a
 
      1st Dec 2008
Widths are tricky... Check out this link...

http://support.microsoft.com/default.aspx/kb/214123
--
HTH...

Jim Thomlinson


"Neal Zimm" wrote:

> HI all,
> The worksheets in my app must be printed on paper about 7 inches wide in a
> font size of at least 18 or 20 to be read in very dim lighting. Column
> widths are fixed.
>
> If a macro generated text string does not 'fit' into the designated cells
> in 1 row, I use more than 1 row to hold the text after spliting it into
> 'words'.
>
> I'm trying to AVOID building a function to return the width of a character
> string in inches, for a few font sizes and 1 to 3 font names.
>
> .Shrinktofit on its own doesn't seem to help.
>
> 1. I can't find a way to test, If OneCell.Shrinktofit = true then Did
> Excel actually shrink the cell contents ? This would help.
>
> 2. Is a call available to MSword that returns the width in inches of a
> string, where its input is the font name and size of the characters? (It's
> gotta be there, but is it available to mortals? I've also posted this on the
> Word bulletin board.)
>
> 3. What might other 'stuff' be that I might be able to use?
>
> Thanks.
> --
> Neal Z

 
Reply With Quote
 
Neal Zimm
Guest
Posts: n/a
 
      4th Dec 2008
Dear Jim,
Thanks for the article. I knew about most of it already. In the addin I'm
developing @ workbook open I set the Options standard font to Arial size 10
in order to get a certain quantity of characters into a 'standard' cell width
in my app.

A bloke from England responding to the same question in the MS Word bulletin
board actually came up with an idea that I've turned into the steps below
that WILL work for me WELL in Excel. The key is to AUTOFIT a column width.

Dim StringArray() As String
Dim RowCount as integer

Use off screen 'unused' column as test vehicle.
Set column width property to autofit.
value .screenupdating to false

set width of column to standard width

put entire character string of words into cell
rowcount =1
redim stringarray(rowcount)

see how col width has changed

current width <= standard is good, no additional rows needed
use stringarray(rowcount) to hold first row's words. rowcount ubound
of stringarray is 1 for needed rows.

current width > standard width
remove words from end of string and save in WordsToGo string
var until current col width <= standard col to get words in the row.
stringarray(rowcount) holds first row's group of words
rowcount = rowcount + 1
redim preserve stringarray(rowcount)

repeat above until WordsToGo string is null and the ubound of
stringarray is rowcount, what's needed to hold the entire string, and the
elements of stringarray are for each row's text holding cell.

Autofit the column, great idea as measuring tool.
Neal





--
Neal Z


"Jim Thomlinson" wrote:

> Widths are tricky... Check out this link...
>
> http://support.microsoft.com/default.aspx/kb/214123
> --
> HTH...
>
> Jim Thomlinson
>
>
> "Neal Zimm" wrote:
>
> > HI all,
> > The worksheets in my app must be printed on paper about 7 inches wide in a
> > font size of at least 18 or 20 to be read in very dim lighting. Column
> > widths are fixed.
> >
> > If a macro generated text string does not 'fit' into the designated cells
> > in 1 row, I use more than 1 row to hold the text after spliting it into
> > 'words'.
> >
> > I'm trying to AVOID building a function to return the width of a character
> > string in inches, for a few font sizes and 1 to 3 font names.
> >
> > .Shrinktofit on its own doesn't seem to help.
> >
> > 1. I can't find a way to test, If OneCell.Shrinktofit = true then Did
> > Excel actually shrink the cell contents ? This would help.
> >
> > 2. Is a call available to MSword that returns the width in inches of a
> > string, where its input is the font name and size of the characters? (It's
> > gotta be there, but is it available to mortals? I've also posted this on the
> > Word bulletin board.)
> >
> > 3. What might other 'stuff' be that I might be able to use?
> >
> > Thanks.
> > --
> > Neal Z

 
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
Calculate Width of String, not Length? 'Em' not 'Kearning'? Matt Microsoft Excel Discussion 2 13th Sep 2011 09:03 PM
Column width in inches??? Bob Microsoft Excel Misc 3 1st Sep 2010 02:17 AM
How to calculate "physical" width of string Marcin Waligora Microsoft Dot NET Framework Forms 6 20th Feb 2005 02:22 PM
Calculate the appropriete width of string if RichTextBox Marcin Waligora Microsoft Dot NET Framework Forms 1 26th Oct 2004 01:05 PM
Column width in inches? Bob Newman Microsoft Excel Setup 1 23rd Oct 2003 03:27 AM


Features
 

Advertising
 

Newsgroups
 


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