从useform vba加载的公共数组
Iam创build一个macros,我需要访问在模块中创build和填充useform(button_click动作)的数组。
Private Sub CommandButton1_Click() Dim tmojo As Worksheet Dim mojocell As Range Set tmojo = Sheets("table mojo") colls = tmojo.Range("N1").End(xlToLeft).Column i = 1 For Each cCont In Me.Controls If TypeName(cCont) = "ComboBox" Then If cCont.Enabled = True Then If cCont.Value = Empty Then MsgBox "you havent specified all the columns" Exit Sub End If ReDim Preserve collname(i) collname(i) = cCont.Value i = i + 1 End If End If Next cCont Call createregion End Sub
我用来自多个combobox(列名)的值填充数组collname。 然后我想调用位于模块中的createregion sub,我想访问collname()中的值。 即时通讯错误说:
Constants, fixed-length strings, arrays, user-defined types, and Declare statements not allowed as Public members of an object module
我需要访问这个数组在多个潜艇,是否有任何解决方法?
谢谢你正手。
正确的方法是将您的UserForm代码转换为常规模块 ,并在模块的顶部将您的数组声明为public,在每个subs之前:
Public MyArr()
当你传送你的代码时,你需要调用你的用户窗体的事件 ,所以改变Me
和Me.
到您的用户窗体的全名 。
如果你缺乏时间,你可以简单地声明UserForm模块的顶部:
Dim MyArr()