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

后端 未结 2 1426
孤城傲影
孤城傲影 2021-01-03 03:50

I\'m programming VBA for Word 2007.

I\'ve created a UserForm which I need to resize with script.

I noticed that its not pixels



        
2条回答
  •  萌比男神i
    2021-01-03 04:50

    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
    

提交回复
热议问题