请注意,此问题与Outlook有关 我是VB中的业余程序员 我希望自定义消息框的按钮标题为“无论如何发送”和“不发送”。
但是现有的消息框无法更改文本。
所以我做了一个自定义表格。现在我想从CommandButton1_Click()Sub
返回一个布尔值这是我的主要子调用表格:
Public Result1 As Boolean
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Const MAX_ITEM_SIZE As Long = 5242880
Result1 = True
Dim FileSize As Long
For Each Item In Item.Attachments
FileSize = FileSize + Item.Size
Next
If FileSize > MAX_ITEM_SIZE Then
UserForm1.Show
'Cancel = True
Cancel = Result1
End If
End Sub
This is my code for click event handler:
Private Sub CommandButton1_Click()
Unload Me
End Sub
请告知如何在Outlook中的MsgBox按钮上实现自定义标题
答案 0 :(得分:1)
我将使用Tag
对象的UserForm
属性将值传递回其调用子
这意味着您希望在其代码窗格中使用UserForm Hide()
方法而不是Unload
方法,而不是放弃其州,即所有属性值(和方法调用),
所以我要按照以下步骤进行:
为Userform1按钮提供有意义的名称
例如,让我们重命名 SendBtn
,该按钮具有" Send Anyway"字幕
DoNotSendBtn
,该按钮具有"不发送"字幕
您实际上可以使用您想要的任何名称(即使CommandButton1
和CommandButton2
会这样做),但要与其相应的事件处理程序名称的所选名称一致
为他们分配以下点击事件处理程序
Private Sub DoNotSendBtn_Click() '<--| change "DoNotSendBtn" to your actual chosen button name
Me.Tag = "True" '<--| store in userform 'Tag' property the value that will be read to cancel the email sending
Me.Hide '<-- this will hide the userform, thus not loosing its "state" -> 'Tag' property will still be available to the calling sub
End Sub
Private Sub SendBtn_Click()'<--| change "SendBtn" to your actual chosen button name
Me.Tag = "False" '<--| store in userform 'Tag' property the value that will be read to let the email sending go on its way
Me.Hide '<-- this will hide the userform, thus not loosing its "state" -> 'Tag' property will still be available to the calling sub
End Sub
最后,更改您的ItemSend
事件处理程序,如下所示
Option Explicit
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Const MAX_ITEM_SIZE As Long = 5242880
Dim FileSize As Long
For Each Item In Item.Attachments
FileSize = FileSize + Item.Size
Next
If FileSize > MAX_ITEM_SIZE Then
UserForm1.Show '<--| show the userform
Cancel = UserForm1.Tag = "True" '<--| 'Cancel' will be set to 'True' if the userform TAG property value is "True", otherwise it'll be set to 'False'
Unload UserForm1 '<--| now unload the Userform (and loose its "state", which you don't need any more)
End If
End Sub