如何在Excel VBA中居中输入框

时间:2018-08-07 02:18:44

标签: excel-vba userform

场景

我使用以下代码输入框

total = Application.InputBox(prompt:="Please key in the total value", Title:="", Type:=2)

问题

输入框随机出现在屏幕的各个角落。

我需要的

我需要此输入框与用户窗体或屏幕的中心对齐。有人知道吗?

1 个答案:

答案 0 :(得分:1)

以上问题已通过这种方式解决

total = Application.InputBox(prompt:="Please key in the total value", left:=(Application.Width / 2), top:=(Application.Height / 2), Title:="", Type:=2)

赋予lefttop属性。可以通过获取Application.widthApplication.height来找到它。将这些值除以2即可将输入框大致移至中心,而不考虑屏幕大小

编辑1

我认为问题已经解决。但是当我使用不同的系统时,它并不稳定。因此希望有人可以为此提供帮助

相关问题