簡體   English   中英

在 CreateObject(“WScript.Shell”) 創建的彈出消息框中插入新行

[英]Insert a new line in a pop up message box created by CreateObject(“WScript.Shell”)

對不起,但我試圖找到幾個小時的答案,但無法弄清楚。 我嘗試使用 vbNewLine 和 vbCrLf 但無法使其在 function 和 function 調用中工作。

如何使用下面的代碼添加新行?

試過這個,但沒有奏效:

checker = MessageTimeOut("Underlying raw data in the workbook has been updated." & vbNewLine & "This will close automatically.", "UPDATE RAW DATA - COMPLETED", 5) 

也試過:

checker = MessageTimeOut("Underlying raw data in the workbook has been updated." & vbCrLf & "This will close automatically.", "UPDATE RAW DATA - COMPLETED", 5)

我想要“這將自動關閉”。 顯示在新行中。

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)

編輯:我之前的答案沒有使用 mshta,我認為您需要它來使您的消息異步並允許您的代碼繼續......

這可以解決問題:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM