- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要一个不会停止宏的消息框。有没有办法插入换行符,与 msgbox 的“vbNewLine”相同?
这些都不起作用:
Chr(13)
Chr(10)
vbLf
vbCr
vbCrLf
vbNewLine
"<br>"
Function mshta(ByVal MessageText As String, Optional ByVal Title As String, Optional ByVal PauseTimeSeconds As Integer)
'mshta.exe as an alternative for msgbox
'[...] some other stuff
Dim ConfigString As String
Set WScriptShell = CreateObject("WScript.Shell")
ConfigString = "mshta.exe vbscript:close(CreateObject(""WScript.Shell"")." & "Popup(""" & MessageText & """," & PauseTimeSeconds & ",""" & Title & """))"
WScriptShell.Run ConfigString
End Function
如果我计算该函数:
mshta "Hello<magic?>World"
我希望它显示:
Hello
World
最佳答案
这里是一个支持回车的解决方案,它使用 API 调用而不是 WScript.Shell,并且可以在 Excel VBA 中工作。它支持标准枚举参数,例如vbQuestion + vbYesNo
,并且可以返回用户响应。如果超时则返回32000
。
这还有一个优点,即在应用程序所在的同一显示器上显示弹出窗口,而不是在主显示器上。
' This part needs to be at the top of a VBA module
#If Win64 Then
Private Declare PtrSafe Function MsgBoxTimeout _
Lib "user32" _
Alias "MessageBoxTimeoutA" ( _
ByVal hwnd As LongPtr, _
ByVal lpText As String, _
ByVal lpCaption As String, _
ByVal wType As VbMsgBoxStyle, _
ByVal wlange As Long, _
ByVal dwTimeout As Long) _
As Long
#Else
Private Declare Function MsgBoxTimeout _
Lib "user32" _
Alias "MessageBoxTimeoutA" ( _
ByVal hwnd As Long, _
ByVal lpText As String, _
ByVal lpCaption As String, _
ByVal wType As VbMsgBoxStyle, _
ByVal wlange As Long, _
ByVal dwTimeout As Long) _
As Long
#End If
Sub TestMsgbox()
Dim ReturnValue
ReturnValue = MsgBoxTimeout(0, "Do you like this message?" & vbCrLf & "This message box will be closed after 4 seconds." & vbCrLf & vbCrLf & "(See Immediate window for return value)", "Return Choice", vbQuestion + vbYesNoCancel, 0, 4000)
Select Case ReturnValue
Case vbYes
Debug.Print "You picked Yes."
Case vbNo
Debug.Print "You picked No."
Case vbCancel
Debug.Print "You picked Cancel."
Case 32000
Debug.Print "Timeout before user made selection."
End Select
End Sub
更多信息: https://www.extendoffice.com/documents/excel/3836-excel-message-box-timer-timeout.html
关于excel - 如何在 'mshta.exe'弹出窗口中插入断行(VBA宏)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54253640/
最近我试图使用 mshta 从 javascript 获取一个快速警告框,但我注意到一些奇怪的事情,我不知道问题是什么。在某种程度上,这就是我试图实现的目标: mshta javascript:ale
我需要一个不会停止宏的消息框。有没有办法插入换行符,与 msgbox 的“vbNewLine”相同? 这些都不起作用: Chr(13) Chr(10) vbLf vbCr vbCrLf vbNewLi
在批处理文件中,我可以得到以下内容,给我一个带有“确定”按钮的消息框 mshta.exe vbscript:Execute^("msgbox ""Registers NOT submitted""&
我希望能够在 32 位和 64 位版本的 mshta.exe 中启动 page.hta。 创建文件 c:\page.hta Test Page var elem = [ "UserAgent=
我是一名优秀的程序员,十分优秀!