|
こんにちは。
(何型の配列を渡したいのか不明なので3例ほど)
UserForm1モジュール
------------------------------------------------------------------------
Option Explicit
'Showの前にUserForm2側のプロシージャを使って配列を渡す
Private Sub CommandButton1_Click()
Dim sAR(2) As String
Dim lAR(2) As Long
Dim vAR As Variant
sAR(0) = "A"
sAR(1) = "B"
sAR(2) = "C"
lAR(0) = 1
lAR(1) = 2
lAR(2) = 3
vAR = Array("XX", "YY", "ZZ")
With UserForm2
Call .ArraySet(sAR(), lAR(), vAR)
.Show
End With
End Sub
UserForm2モジュール
---------------------------------------------------------------------
'変数宣言はDimでOK
Option Explicit
Dim StrT() As String
Dim LngT() As Long
Dim VntT As Variant
'配列を受け取るプロシージャ
Sub ArraySet(STmp() As String, LTmp() As Long, VTmp As Variant)
StrT = STmp
LngT = LTmp
VntT = VTmp
End Sub
'確認用
Private Sub CommandButton1_Click()
Dim V As Variant
For Each V In StrT
MsgBox V
Next V
For Each V In LngT
MsgBox V
Next V
For Each V In VntT
MsgBox V
Next V
End Sub
ちょっとややこしいけど
標準モジュールはできれば使いたくないので・・・
※例なので
String,Long,Variantの三つを同時に書いています。
必要なところだけに絞って下さい。
|
|