What are the units for form widths and heights in VBA?

情到浓时终转凉″ 提交于 2019-11-30 22:03:46

When manipulating controls on forms through code the sizes are in twips by default (I believe if you change the form's ScaleMode property you can choose to use another unit).

Your conversion formula is wrong (it's easy to get wrong). Try this, wrapped in a function to avoid code duplication with potential for typos in every duplicate

Function nTwipsFromPixelsX(ByVal nPixels As Long) As Long
  nTwipsFromPixels = TwipsPerPixelX() * nPixels
End Function

When using VBA for Access, you usually express sizes in twips and/or centimeters, depending if you manage them from the user interface (centimeters) or from code (twips). As an example, you could set the column size for a combobox control in centimeters (by entering the corresponding values in the control's properties when the form is in design mode) or in twips (by updating these values from code while the form is open).

I guess this will also apply to VBA for Word. I'd advise you to write down both cmToTwips and TwipsToCm functions to make your measure conversions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!