VBA 中表单宽度和高度的单位是什么?
我正在为 Word 2007 编写 VBA。
我创建了一个用户窗体,需要使用脚本调整其大小。
我注意到它不是像素
Me.Width = pixelW // form appears about 20% larger than the pixel width
也不是缇
Me.Width = (((1 / TwipsPerPixelX()) * pixelW)) / 1) // form appears very small
那么在 Office 2007 VBA 中如何测量表单宽度和高度呢?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 VBA for Access 时,通常以缇和/或厘米为单位表示尺寸,具体取决于是从用户界面(厘米)还是从代码(缇)管理它们。例如,您可以以厘米为单位设置组合框控件的列大小(通过在窗体处于设计模式时在控件的属性中输入相应的值)或以缇为单位(通过在窗体打开时从代码更新这些值) 。
我想这也适用于 Word 的 VBA。我建议您写下 cmToTwips 和 TwipsToCm 函数来进行度量转换
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
当通过代码操作表单上的控件时,默认情况下大小以缇为单位(我相信如果您更改表单的 ScaleMode 属性,您可以选择使用其他单位)。
你的转换公式是错误的(很容易出错)。试试这个,包装在一个函数中,以避免代码重复,每个重复都可能出现拼写错误
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