Width of text added to a control
Probably an easy question, but...
I desire to paste a certain text string into an Excel Spreadsheet Cell. If the text is wider (in pixels) than the receiving cell's width, the text should be broken and continued in the cell below the receiving cell. Is there a way to determine the width of the text string (in pixels?). I am constrained by an existing EXCEL Spreadsheet layout and cannot change the Font of the text I am printing nor can I exceed the width of the existing cell.
Thanks...
Re: Width of text added to a control
Not that easy :)
There is the builtin VB TextWidth method - however, this applies to :
- Forms (eg. Form1.TextWidth("some text"))
- PictureBox
- Printer Object
- Property Page Object
- UserControl object
- UserDocument object
- and of course, don't forget that the size in pixels relates to the font that is being used for that object.
You'll need to capture the size (width) of the string before you paste it over to Excel - then of course, you'll need to find out how big the cell is in Excel (in pixels) and do some calculations on the String to see where to split it up.
Good luck
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb