Autoshape not accurate?

tball

New Member
Joined
Aug 12, 2002
Messages
45
I used the following subroutine to draw a rectangle on the screen. It should be anchored at 50,50 and be 50 wide by 50 tall but when I check it, its not. its achored at 49.8,49.8 and is 50.4 wide by 50.4 tall.

Does anyone else have this problem and if so is there an easy fix?

Thanks
tball


Sub drawTest()

ActiveSheet.Shapes.AddShape(msoShapeRectangle, 50, 50, 50, 50).Select

MsgBox Selection.Top & "<>" & Selection.Height & "<>" & Selection.Left & "<>" & Selection.Width

End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hi tball,

I believe the "problem" is that the Height, Width, Top, and Left properties are specified in points, which are units of 1/72 inch. However, the values you specify must be a whole number of screen pixels, where the size of a pixel is determined by your screen resolution setting. The most common setting for this is 96 pixels/inch. In this case the each point would be 96/72 pixel.

I believe your screen resolution is set to 120 pixels per inch, also a very common setting. With this setting a Top or Left value of 50 points would be 50 x 120 / 72 pixels, or 83.333 pixels. But the number of pixels has to be a whole number so the number of points must be reduced to the value that corresponds to 83 pixels, which gives 83 x 72 / 120 points or 49.8 points. This explains why you get this value when you set a value of 50 points.

All this just means that any value you set in points will be converted to the nearest value in pixels, which sometimes forces the point you set to have to be adjusted slightly. This will not be noticeable on the screen, however, since the resolution of the screen is one pixel, and the adjustments are always a fraction of a pixel.
 
Upvote 0

Forum statistics

Threads
1,218,944
Messages
6,145,357
Members
450,611
Latest member
JodiWe

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top