- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
对于这个函数的 Top 和 Left 参数,是否有一个中心屏幕选项,或者它总是一个数字?
我使用它而不是常规输入框,因为它可以更好地处理取消事件,但它总是出现在屏幕的右下角,这不太有用:/
最佳答案
没有中央屏幕选项。你得计算一下。但是,假设您使用的是 Excel 2007 或更高版本,还有另一个问题......
这对我来说是新闻,但在谷歌搜索和测试中,我看到在 Excel 2007 和 2010 Application.Inputbox 恢复到它的最后一个位置,而忽略了顶部和左侧设置。即使从新工作表调用新输入框,此问题似乎仍然存在。当我在 XL 2003 中尝试它时,它可以正常工作,并且输入框放置在正确的左右坐标处。
您可以将输入框拖动到您想要的位置,然后保存。除非有人稍后拖动它,否则它将在同一个地方重新打开。
这是 link to a solution这有助于某人恢复正确的行为,并且还解决了将输入框居中的问题。它确实需要 API 调用,因此请在尝试之前保存您的工作。
编辑 - 根据 JMax 的评论,这是上面链接中的代码。它是由 vbforums.com 网站上名为 KoolSid 的用户编写的:
Private Declare Function UnhookWindowsHookEx Lib "user32" _
(ByVal hHook As Long) As Long
Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Private Declare Function SetWindowsHookEx Lib "user32" _
Alias "SetWindowsHookExA" (ByVal idHook As Long, _
ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Private Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As Long
'~~> Handle to the Hook procedure
Private hHook As Long
'~~> Hook type
Private Const WH_CBT = 5
Private Const HCBT_ACTIVATE = 5
'~~> SetWindowPos Flags
Private Const SWP_NOSIZE = &H1 '<~~ Retains the current size
Private Const SWP_NOZORDER = &H4 '<~~ Retains the current Z order
Dim InputboxTop As Long, InputboxLeft As Long
Sub TestInputBox()
Dim stringToFind As String, MiddleRow As Long, MiddleCol As Long
hHook = SetWindowsHookEx(WH_CBT, _
AddressOf MsgBoxHookProc, 0, GetCurrentThreadId)
'~~> Get the center cell (keeping the excel menus in mind)
MiddleRow = ActiveWindow.VisibleRange.Rows.Count / 1.2
'~~> Get the center column
MiddleCol = ActiveWindow.VisibleRange.Columns.Count / 2
InputboxTop = Cells(MiddleRow, MiddleCol).Top
InputboxLeft = Cells(MiddleRow, MiddleCol).Left
'~~> Show the InputBox. I have just used "Sample" Change that...
stringToFind = Application.InputBox("Sample", _
"Sample", "Sample", InputboxLeft, InputboxTop, , , 2)
End Sub
Private Function MsgBoxHookProc(ByVal lMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
If lMsg = HCBT_ACTIVATE Then
'~~> Change position
SetWindowPos wParam, 0, InputboxLeft, InputboxTop, _
0, 0, SWP_NOSIZE + SWP_NOZORDER
'~~> Release the Hook
UnhookWindowsHookEx hHook
End If
MsgBoxHookProc = False
End Function
关于Excel Application.InputBox 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8466002/
我让用户输入下限和上限,然后我用它来过滤行。例如,如果他们为下限输入 4,为上限输入 8,然后我使用这些数字来过滤第一个单元格中包含 4、5、6、7 或 8 的行。 我的代码(我将在下面显示)确保用户
我的目标是在 InputBox 崩溃时重新运行它,并给用户另一个机会来提供正确的输入类型。 (就像它崩溃一样,你会得到一个消息框,上面写着“抱歉你的条目不可用,请重试”,然后它会跳回输入框。) Tes
我有一个带有以下代码的 Excel VBA 文件。我的问题是 InputBox不能正常工作。有10床单。第一张表称为“菜单”。其他工作表如工作表 2 - 10。应用工作表 3,4 和 5 VeryHi
这个问题在这里已经有了答案: How to identify between ok and cancel button in inputbox (3 个答案) 关闭 8 年前。 当按下取消按钮时,如
因此,此代码将一直有效,直到您决定点击取消或使用 X 关闭输入框窗口,此时它会为您提供: 运行时错误“424”: 需要对象 然后它会在调试中突出显示这部分代码: Set ranC = Applicat
我正在开发一款名为 BatchOS 的批处理游戏,它基本上模仿了实际的操作系统。当我为 BatchOS 制作 Internet Explorer 时。我找到了我必须要的东西。我如何批量居中输入框?就像
我想创建一个 msgbox根据 input box 中的特定条目显示文本. 请参阅下面的示例代码,其中将值输入 input box ,“Fantastic”或“Rubbish”,收到不同的信息。 Di
任何人请告诉我,如何允许用户在输入框中只输入文本。我想使用 应用程序.输入框 vba 代码中的命令。 最佳答案 就像是: Sub GiveMeData() Dim s As String
对于这个函数的 Top 和 Left 参数,是否有一个中心屏幕选项,或者它总是一个数字? 我使用它而不是常规输入框,因为它可以更好地处理取消事件,但它总是出现在屏幕的右下角,这不太有用:/ 最佳答案
您好,这是我在这里的第一个问题,我是 VBA 编程的新手。我正在寻找一个 VBA 代码,当我在一系列单元格上选择一个单元格时,它允许我弹出一个输入框来放置一些值。 例如,当我从 B 列中选择一个单元格
我希望用户通过 Application.InputBox 和 Type:=8 选择范围。 我给它一个默认范围,但在某些情况下它会显示意外行为并预选一个不同的错误默认范围。 我的示例代码: Dim my
我有一个运行良好的宏。但是我遇到的问题是InputBox。当用户在InputBox中按下 CANCEL 或 X 时,宏运行出错。我该怎么做才能阻止这种情况的发生。如果用户按下 X 或取消,则过程应结束
每当我使用 Application.InputBox() 时,我都会调出 VBA 帮助来提醒我要使用哪种 Type: Sub MAIN() Dim s As String s = Ap
我有这段代码,我正在尝试执行一项简单的任务,显然这对我来说并不那么简单。我想说vba要复制哪个工作表(这里是InputBox的功能,我在其中插入工作表名称),然后,如果存在(即如果名称正确),则在sh
此帖为Filling Internet Explorer inputbox的后续 我们试图找出问题所在,但似乎我无法(可能是由于页面中的 JavaScript?- 请查看另一篇文章)正确定位到我想要的
在 AutoHotKey 中,我想要类似 InputBox 的东西,除了文本输入是多行的。 (即像一个文本区域)。 我希望有两个按钮,“确定”和“取消”,并且我希望它们都有加速器。我希望这段代码采用函
InputBox 函数 在对话框中显示提示,等待用户输入文本或单击按钮,并返回文本框内容。 InputBox(prompt[, title][,default][,xpos][,ypos][,h
我正在研究一个宏,它允许我将 SQL 查询键入(或更可能粘贴)到 InputBox 中,然后单击“确定”,它会返回针对数据库的查询结果。问题是,默认情况下 VBA 只接受一行文本,并且 SQL 代码以
我真的搜索了几个小时,但我找不到任何解决方案。 您应该只在输入框中输入数字,并且当您在没有任何数字或字符串的情况下点击 ok 时应该会出现一个 msgbox... 第一部分很简单,但我总是点击 OK
我是 VBA 新手,我正在尝试创建一个宏,它从 inputBox 接受 0 到 1000 之间的数字并将其转换为十六进制。很好,但我正在努力让程序接受该范围(0 - 1000)。这就是发生的事情: 如
我是一名优秀的程序员,十分优秀!