How to insert a break line in 'mshta.exe' pop up (VBA macro)?

后端 未结 1 1792
时光说笑
时光说笑 2020-12-22 04:59

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

None of these works:

Chr(13) 
         


        
相关标签:
1条回答
  • 2020-12-22 05:24

    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
    

    More info: https://www.extendoffice.com/documents/excel/3836-excel-message-box-timer-timeout.html

    0 讨论(0)
提交回复
热议问题