创建电子表格数组

时间:2015-11-04 01:35:49

标签: excel vba excel-vba

我有以下工作表数组:

// Add a "textFieldDidChange" notification method to the text field control.
[textField addTarget:self 
              action:@selector(textFieldDidChange:) 
    forControlEvents:UIControlEventEditingChanged];

当我尝试执行以下操作时:

 Dim ArrayOne(11) As Worksheet
ArrayOne(0) = "January 2015"
ArrayOne(1) = "February 2015"
ArrayOne(2) = "March 2015"
ArrayOne(3) = "April 2015"
ArrayOne(4) = "May 2015"
ArrayOne(5) = "June 2015"
ArrayOne(6) = "July 2015"
ArrayOne(7) = "August 2015"
ArrayOne(8) = "September 2015"
ArrayOne(9) = "October 2015"
ArrayOne(10) = "November 2015"
ArrayOne(11) = "December 2015"

它给了我一个错误:

  

对象变量或未设置块变量

错误点在这里:

Set ArrayOne(1) = Sheets.Add
Sheets.Add.Name = ArrayOne(1)  
ArrayOne(1).Protect DrawingObjects:=False, Contents:=False, _

2 个答案:

答案 0 :(得分:0)

您已将ArrayOne声明为Worksheet类型,但您使用字符串填充它。

应该是这样的:

Dim ArrayOne(11) As Worksheet
Set ArrayOne(0) = Worksheets("January 2015")
Set ArrayOne(1) = Worksheets("February 2015")
'...etc

您不会显示ArrayTwo的来源。

答案 1 :(得分:0)

您尝试将String值分配给Worksheet数据类型。您可以为工作表名称声明String变量,为实际工作表声明Worksheet变量。也许是这样的事情:

Dim strArrayOne(11) As String
Dim wsArrayOne(11) As Worksheet

strArrayOne(0) = "January 2015"
strArrayOne(1) = "February 2015"
strArrayOne(2) = "March 2015"
strArrayOne(3) = "April 2015"

Set wsArrayOne(1) = Sheets.Add
Sheets.Add.Name = strArrayOne(1)