VBA复制单元范围到公共2D阵列

时间:2016-08-02 08:00:27

标签: excel vba

我在AutoCAD中使用VBA,需要从Excel工作表中提取一些数据。

基本上我想:

  • 声明公共2D字符串数组:FULL_TABLE。
  • 在初始化时打开excel文档,然后获取单元格区域 关闭文件。
  • 将单元格区域中的所有值都放到2D字符串数组中 FULL_TABLE

到目前为止我所拥有的:

在第1单元中声明:

 Public FULL_TABLE() As String

不同模块:

Private Sub UserForm_Initialize()

'Excel Path
Dim excelPath As String
excelPath = "O:\myData.xls"

'Open Excel File
Set exapp = CreateObject("Excel.Application")
exapp.Visible = False
exapp.Workbooks.Open (excelPath)
Set wsheet = exapp.ActiveSheet

'Get cell values
'privateFULL_TABLE is not public and can only be accessed here
'If I try to add values to FULL_TABLE (public) I get errors

Dim privateFULL_TABLE As Variant 
privateFULL_TABLE = wsheet.Range("B5:AV50")

'here I can access values correctly from privateFULL_TABLE

'Close File
exapp.Quit
Set exapp = Nothing

End Sub

问题:

如何将一系列单元格转换为公共2D字符串数组?

0 个答案:

没有答案