VBA中的表单宽度和高度单位是什么? [英] What are the units for form widths and heights in VBA?

查看:608
本文介绍了VBA中的表单宽度和高度单位是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为Word 2007编程VBA。



我创建了一个用户窗体,我需要用脚本调整大小。



我注意到它的不是像素

  Me.Width = pixelW //表格比像素宽度大出20%左右

而其不是缇或者

  Me.Width =(((1 / TwipsPerPixelX())* pixelW))/ 1)小

那么如何在Office 2007 VBA中测量表格宽度和高度?

$ b $当通过代码操作窗体上的控件时,默认情况下大小的大小是缇(我相信如果更改表单的ScaleMode属性,则可以选择使用另一个单位) 。

您的转换公式不正确(很容易出错)。试试这个,用一个函数包装,以避免代码重复,每个重复都有可能发生拼写错误。

pre code函数nTwipsFromPixelsX(ByVal nPixels As Long) As Long
nTwipsFromPixels = TwipsPerPixelX()* nPixels
End Function


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

 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 form widths and heights measured in Office 2007 VBA?

解决方案

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

这篇关于VBA中的表单宽度和高度单位是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆