VBAを色々と垣間見る

UserForm の機能

別のフォームに送る

message

書き方や書く場所で。


◆Sheet1
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Range("c3").Value = "go" Then
        callstart
    End If
    Range("c3").Value = ""
End Sub

Sub callstart()
    Load UserForm1
    Load UserForm2
    UserForm1.Show
End Sub

◆UserForm1
Option Explicit
Dim str As String
Private Sub CommandButton1_Click()  ' 送信
    send (TextBox1.Text)
End Sub

Sub send(haru As String)
    UserForm2.TextBox2.Text = haru
    TextBox2.Text = "春美より「" & haru & "」を送りました。"
    UserForm2.Show
End Sub

Private Sub CommandButton2_Click()  ' クリア
    TextBox1.Text = ""
    TextBox2.Text = ""
End Sub

Private Sub CommandButton3_Click()  ' 閉じる
    Unload UserForm1
End Sub

◆UserForm2
Option Explicit
Dim str_n As String
Private Sub CommandButton1_Click() ' 送信
    UserForm1.TextBox2.Text = TextBox1.Text
    TextBox2.Text = "夏海より「" & TextBox1.Text & "」を受けました。"
    Load UserForm1
    Unload UserForm2
End Sub

Sub uke(natu As String)
    UserForm2.TextBox2.Text = natu
    TextBox2.Text = "「" & natu & "」を送りました。"
    UserForm2.Show
End Sub

Private Sub CommandButton2_Click()  ' クリア
    TextBox1.Text = ""
    TextBox2.Text = ""
End Sub

Private Sub CommandButton3_Click()  ' 閉じる
    Unload UserForm2
End Sub

出稿2019年4月7日

tsuingcom