2

ここに私のsub()があります:

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

両方とも正常な WorkBook にあります。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 に答える