What are the units for width and height of a form in VBA?

I am programming VBA for Word 2007.

I created a UserForm that I need to modify using a script.

I noticed that its not pixels

Me.Width = pixelW // form appears about 20% larger than the pixel width 

And its not twips either

  Me.Width = (((1 / TwipsPerPixelX()) * pixelW)) / 1) // form appears very small 

So, how are the width and height of the form in Office 2007 VBA?

+4
source share
2 answers

When you control the controls through code, the default sizes change (I assume that if you change the ScaleMode property of the form, you can choose another device).

Your conversion formula is wrong (it's easy to make a mistake). Try this by wrapping in a function to avoid code duplication with the possibility of typos in each duplicated

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

When using VBA for access, you usually express the dimensions in tweets and / or centimeters, depending on whether you control them from the user interface (centimeters) or code (twips). For example, you can set the column size for the combobox control in centimeters (by entering the appropriate values ​​in the control properties when the form is in development mode) or in twips (by updating these values ​​from the code while the form is open).

I assume this applies to VBA for Word as well. I would advise you to write cmToTwips and TwipsToCm functions to convert your metrics

+5
source

Source: https://habr.com/ru/post/1302664/


All Articles