消息框中的单词出现在另一行

时间:2018-07-19 10:34:08

标签: excel vba excel-vba

我使用以下VBA打开消息框:

Sub Message()
MsgBox ("Do you want create a file on your desktop?" _
& vbCr & " " _
& vbCr & "Once you click yes an unprotected file with all sheets visible will be saved on your desktop and opened. You can immediately start working with this file.")
End Sub

所有这些都很好。


enter image description here

但是,如您在屏幕快照中所见,“文件”一词位于另一行。是否可以格式化messagebox或更改VBA代码,以使“文件”一词不会出现在不同的行中?

2 个答案:

答案 0 :(得分:3)

这取决于用户PC的分辨率。就我而言,我什至是这样的:

enter image description here

如果要控制行,则应编写一个自定义表单。在那里,您将可以更好地控制显示,并且如果您对其显示属性有所了解,则可以精确模拟MsgBox()

enter image description here

一些示例代码Label1是一个标签元素:

Private Sub UserForm_Initialize()

    Me.Label1 = "Do you want create a file on your desktop?" _
            & vbCr & " " _
            & vbCr & "Once you click yes an unprotected file with all sheets visible will be saved on your desktop and opened." & _
            vbCrLf & "You can immediately start working with this file."

End Sub

答案 1 :(得分:1)

也许可以使用换行符来调整代码以适合您的情况。例如:

Sub Message()
MsgBox ("Do you want create a file on your desktop?" _
& vbCr & " " _
& vbCr & "Once you click yes an unprotected file" _
& vbCr & " " _
& vbCr & "with all sheets visible will be saved on your desktop and opened." _
& vbCr & " " _
& vbCr & "You can immediately start working with this file.")
End Sub