2

这是我的子():

Sub SendEmail()

MyPrompt = "want to add a message?"
Mysubject = PopMessage(MyPrompt)

End Sub

这是我的函数():

Public Function PopMessage(ByVal Mypromt As String) As String
'Open a existing userform with a MyPrompt MsgBox and catch user text

FormName = "UserForm1" ' choose here the desired UserForm
Dim Mytext As String
Mytext = ""

On Error Resume Next
MsgBox (MyPrompt) ' only for debuging
Response = MsgBox(Prompt:=MyPrompt, Buttons:=vbYesNo)
    If Response = vbYes Then
    If UserForm1 Is Nothing Then ' we want to check if userform exists
        MsgBox ("Le Formulaire n'existe pas")
        Exit Function
   End If
        Unload UserForm1 ' first we clear the userform
        UserForm1.Show
        Mytext = UserForm1.TextBox1.Text
    End If

End Function

两者都在理智的工作簿中。MsgBox(MyPrompt) 返回空。谢谢你的帮助。

4

2 回答 2

2

为什么你应该使用的经典案例Option explicit

你看有什么不同吗?;)

Public Function PopMessage(ByVal Mypromt As String) As String

MsgBox (MyPrompt)

有趣的阅​​读(第 2 点)

这解释了您所面临的完全相同的问题。

于 2013-10-04T08:21:37.710 回答
0

嗯....一个错字会让你头疼

我同意总是声明变量是一个好习惯

于 2013-10-04T08:26:09.947 回答