问题
Sorry but I was trying to find the answer for hours but could not figure it out. I tried playing with vbNewLine and vbCrLf but could not make it to work in the function and in the function call.
How do I add a new line with the code below?
Tried this but it did not work:
checker = MessageTimeOut("Underlying raw data in the workbook has been updated." & vbNewLine & "This will close automatically.", "UPDATE RAW DATA - COMPLETED", 5)
Also tried:
checker = MessageTimeOut("Underlying raw data in the workbook has been updated." & vbCrLf & "This will close automatically.", "UPDATE RAW DATA - COMPLETED", 5)
I want the "This will close automatically." shown in a new line.
Function MessageTimeOut(str_message As String, str_title As String, int_seconds As Integer) As Boolean
Dim Shell
Set Shell = CreateObject("WScript.Shell")
Shell.Run "mshta.exe vbscript:close(CreateObject(""WScript.shell"").Popup(""" & str_message & """," & int_seconds & ",""" & str_title & """))"
MessageTimeOut = True
End Function
Sub Some_Sub()
' some lengthy code....
Dim checker As Boolean
checker = MessageTimeOut("Underlying raw data in the workbook has been updated. This will close automatically.", "UPDATE RAW DATA - COMPLETED", 5)
回答1:
EDIT: My previous answer wasn't using mshta which I think you needed in order to make your message asynchronous and allow your code to continue...
This does the trick:
Sub Test2()
mshta "Me`s`s`age", "test", 5 '<<< all backticks become newlines
Debug.Print "This runs right away"
End Sub
Function mshta(ByVal MessageText As String, Optional ByVal Title As String, _
Optional ByVal PauseTimeSeconds As Integer)
Dim ConfigString As String, WScriptShell
Set WScriptShell = CreateObject("WScript.Shell")
ConfigString = "mshta.exe vbscript:close(CreateObject(""WScript.Shell"").Popup(Replace(""" & MessageText & """,""`"",vbLf)," & PauseTimeSeconds & ",""" & Title & """))"
WScriptShell.Run ConfigString
End Function
来源:https://stackoverflow.com/questions/61750883/insert-a-new-line-in-a-pop-up-message-box-created-by-createobjectwscript-shell