vba VBA中表格宽度和高度的单位是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2351151/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are the units for form widths and heights in VBA?
提问by TheFlash
I'm programming VBA for Word 2007.
我正在为 Word 2007 编写 VBA。
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 twipseither
而其不缇要么
Me.Width = (((1 / TwipsPerPixelX()) * pixelW)) / 1) // form appears very small
So how are form widths and heights measured in Office 2007 VBA?
那么在 Office 2007 VBA 中如何测量表单的宽度和高度呢?
回答by MarkJ
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).
通过代码操作窗体上的控件时,默认情况下大小以缇为单位(我相信如果您更改窗体的 ScaleMode 属性,您可以选择使用其他单位)。
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
回答by Philippe Grondier
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).
使用 VBA for Access 时,通常以缇和/或厘米表示大小,具体取决于您是从用户界面(厘米)还是从代码(缇)管理它们。例如,您可以以厘米为单位设置组合框控件的列大小(通过在表单处于设计模式时在控件的属性中输入相应的值)或以缇为单位(通过在表单打开时从代码更新这些值) .
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
我想这也适用于 Word 的 VBA。我建议你写下 cmToTwips 和 TwipsToCm 函数来进行度量转换