I have a report generator in Excel VBA, which works so far. It reads some input data and produces a formatted Excel sheet as result. The last column of this sheet is filled with some kind of free text.
Now, sometimes the free text does not fit into the last column, it is just too wide. Since the row height of all rows of this report is fixed, I cannot set range.WrapText=True
for this column (to let the text stay visible, one would have to increase the row height). A manual (non-VBA) solution is easy: split the text into several parts and spread it over different rows. For example:
A | B |C
content |This text is too wide for column B.
here |This text fits. |
is | |
fixed | |
should be transformed into
A | B |C
content |This text is too |
here |wide for column |
is |B. |
fixed |This text fits. |
I could easily code that if I would be able to determine the real text width (using a proportional font!) of the content in column B using VBA. range.ColumnWidth
gives me the actual width of the column, but I have no idea how I determine the width of "This text is too wide for column B." in VBA. Any suggestions?
(I am currently using Excel 2002 / XP).