如何在"mshta.exe"弹出窗口(VBA宏)中插入换行符? [英] How to insert a break line in 'mshta.exe' pop up (VBA macro)?

查看:236
本文介绍了如何在"mshta.exe"弹出窗口(VBA宏)中插入换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个不停止宏的msgbox.有没有一种方法可以插入一条换行符,与msgbox的'vbNewLine'相同?

I need a msgbox that does not stop the macro. Is there a way to insert a break line, same as 'vbNewLine' for msgbox?

这些作品都不是

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

如果我对函数进行校准:

If I cal the function:

mshta "Hello<magic?>World"

我希望它显示:

Hello
World

推荐答案

以下是一种支持回车的解决方案,该回车使用API​​调用而不是WScript.Shell,并且可以在Excel VBA中使用.它支持标准的枚举参数,例如vbQuestion + vbYesNo,并且可以返回用户响应.如果发生超时,则返回32000.

Here is a solution that supports carriage returns that use an API call instead of WScript.Shell and works in Excel VBA. It supports standard enumerated parameters like vbQuestion + vbYesNo and can return the user response. 32000 is returned if the timeout occurs.

这还具有在与应用程序相同的监视器上而不是在主显示屏上显示弹出窗口的优点.

This also has the advantage of showing the popup on the same monitor as the app instead of the main display.

' 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/document/excel/3836-excel-message-box-timer-timeout.html

这篇关于如何在"mshta.exe"弹出窗口(VBA宏)中插入换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆