在设置焦点的两种forms之间的Excelmacros数据传递

我有两种forms。 form1有四个文本框和每个文本框的button。 该button将设置焦点在文本框,并调出form2form2基本上是一个数字键盘,也有一个文本框,以便用户可以select一个数字。 这个数字将在form2.textbox ,当更改时将数据放在form1.textbox1

我遇到的问题是如何告诉form2.textbox把数据放在form1.textbox2

这是我的代码看起来像:

 Public Sub textbox1_Click() Me.textbox1.SetFocus numbfrm.Show End Sub Private Sub textbox2_Click() Me.textbox2.SetFocus numbfrm.Show End Sub Private Sub textbox3_Click() Me.txtactual.SetFocus numbfrm.Show End Sub 

这是数字forms。 它包含所有的数字1到10,但我只是把前三个数字在这里。

 Private Sub Cmd1_Click() TxtNumber.Value = TxtNumber.Value & "1" End Sub Private Sub Cmd2_Click() TxtNumber.Value = TxtNumber.Value & "2" End Sub Public Sub TxtNumber_Change() passnumber End Sub 

这是在一个模块中:

 Sub passnumber() form1.textbox1.Value = numbfrm.TxtNumber End Sub 

我一直在通过networking寻找一个简单的方法来做到这一点。 我试着在模块中

 Sub passnumber() If form1.texbox1.foucs =true then form1.textbox1.Value = numbfrm.TxtNumber Else If form1.textbox2.foucs = true then form1.texbox2.value =numbfrm.txtnumber End sub 

我已经为它做了一个解决方法,我把切换button旁边的每个框,当button被按下时,它会标记为真,然后我告诉它,如果该切换是真实的,它会使用某些文本框

 Sub passnumber() If form1.option1.value =true then form1.textbox1.Value = numbfrm.TxtNumber else If form1.option2.value =true then form1.textbox2.Value = numbfrm.TxtNumber end if end if End sub