Column width in pixels how?
Hi Robbie,
COLUMNWIDTH: One unit of column width is equal to the width of one character
in the Normal style.
range("A1").Columnwidth
returns 8.43 characters
WIDTH: Returns or sets an object's width, in points.
range("A1").width
returns 48 points. 72 point/inch=.6666"=64 pixels @ 96 pixels/inch
So...
Sub testwidth()
Sheets("sheet3").Activate
screenres = 96 '96/inch
mypoints = Sheets("sheet3").Range("A1").Width
' returns 48 points
mychars = Sheets("sheet3").Range("A1").ColumnWidth
' returns 8.43 chars
mypixels = (mypoints / 72) * screenres 'pixel width of column
Debug.Print mypoints, mychars, mypixels
' returns 48 8.43 64
End Sub
The column width is 48 points or 8.43 characters or 64 pixels.
I couldn't get ActiveWindow.PointsToScreenPixelsX to return anything but
zero.
--
John
johnf202 at hotmail dot com
"robbie de sutter" wrote in message
...
Hello,
How can I determine the column width in pixels in VBA (excel 2002 sp2)?
In a new workbook I try to determine the width of column A.
Clicking between 2 columns displays the following information (provided
by excel - the pixel value is in this case correct):
"Width: 8.43 (64 pixels)"
So I need the value 64 in my VBA code, but HOW?
Allready tried to following:
range("A1").width
returns 48 (?!?!?!)
range("A1").Columnwidth
returns 8.43
ActiveWindow.PointsToScreenPixelsX(range("A1").wid th)
returns 146
ActiveWindow.PointsToScreenPixelsX(range("A1").wid th)
returns 106
Also I have exactly the same problem when trying to determine the row
height...
Can anybody help me?
thanks in advance,
Robbie De Sutter
|