I found a solution, though it didn't work as well as I hoped. I wasn't allowed to post the code, so my comments on it first, and I'll try to wrestle with getting the code up.
The idea here was to create a function that I could use in conditional formatting. In words, the process goes:
- Determine the pixel width of the characters in a cell
- Divide that value by the pixel width of the cell to get an estimate for number of lines
- I ended up having to manually add line breaks in a separate function, because it isn't counted in length calculation
- Compare the estimated number of lines to the height of the cell divided by the height of a 1-line reference cell
So, everything works as expected except InitChrWidths(). The values given here are supposed to be ratios of the font point size to pixel width of the characters. In my testing, I found that these ratios (at least with Calibri, size 11) were horrendously off from what ColumnWidth() gave me, and you can see I tinkered with the values. Basically, I put the characters from each group repeating in a cell that measured 100 px across using ColumnWidth(). I then took to determine the average size of each character in the group. I also put every character from each group in a separate column (one per row) and let excel autosize the column. Taking these two different values, I took different weighted averages until LenInPoints() was extremely close to ColumnWidth(). I also had a cell with all characters for which we assign sizes, and it was pretty close.
But when I tried to copy this to another sheet, I got exceptionally small values for the LenInPoints(), so I'm not sure what's going on. What I do know is that this is not a reliable way to measure Calibri's size. Another thing I tested was choosing a different font size, and the proportions of growth between the letters were not the same. Even changing the zoom state of my view effected how the letters sat in the cells.
I also had the idea to use an average value of the size for all characters -- , but I realized that this wouldn't help either because of the zoom scaling issue, and ended up being more work that it was worth. Still, the ColumnWidth() and RowHeight() functions are useful and took me a surprisingly long time to find, so I'll leave this partial solution here for future generations.
Bookmarks