本文介绍了在由CreateObject("WScript.Shell")创建的弹出消息框中插入新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,但我试图寻找答案已有几个小时,但找不到答案.我尝试使用vbNewLine和vbCrLf,但无法使其在函数和函数调用中正常工作.

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)

也尝试过:

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)

推荐答案

编辑:我以前的答案不是使用mshta,我认为您需要mshta来使消息异步并允许您的代码继续...

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...

这可以解决问题:

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

这篇关于在由CreateObject("WScript.Shell")创建的弹出消息框中插入新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 13:29