VBA 中表单宽度和高度的单位是什么?

发布于 2024-08-23 01:58:10 字数 377 浏览 6 评论 0原文

我正在为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

彼岸花ソ最美的依靠 2024-08-30 01:58:11

使用 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

婴鹅 2024-08-30 01:58:10

当通过代码操作表单上的控件时,默认情况下大小以缇为单位(我相信如果您更改表单的 ScaleMode 属性,您可以选择使用其他单位)。

你的转换公式是错误的(很容易出错)。试试这个,包装在一个函数中,以避免代码重复,每个重复都可能出现拼写错误

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文