我正在尝试使用我的代码调用我的工作表的几个数组。
ThisWorkbook.Sheets(Array("Sheet1", "Sheet3"))
ThisWorkbook.Sheets(Array("Sheet2", "Sheet5"))我想知道是否有任何方法可以设置一个类似于下面的变量:
Dim ArrayOne As String
Dim ArrayTwo As String
ArrayOne = ThisWorkbook.Sheets(Array("Sheet1", "Sheet3"))
ArrayTwo = ThisWorkbook.Sheets(Array("Sheet2", "Sheet5"))
ArrayOne 'Call this Array then save
Filename:="C:\Data\testfile.xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _,
CreateBackup:=False
ArrayTwo 'Call this array then save
Filename:="C:\Data\testfile.xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _,
CreateBackup:=False 如果你能帮助我,请让我知道!
发布于 2014-07-20 20:57:05
根据Arthur的解决方案(上一条评论),我遇到了一个类似的问题(因此达到了这篇文章):我试图创建一个动态数组,它会将Workbook中的一系列工作表保存在一个数组中,然后对该数组执行特定的操作。
不同的是,用户在excel中的一个范围(列)内定义工作表的名称(它们代表另一个宏的场景),但是这个范围可以扩大或缩短。
我使用两个数组,其中我在第一个数组中运行循环,每次都将扩展保存到另一个数组中(出于透明度的原因)。代码:
Sub testArray()
Dim a, b As Integer
scenarios_number = Sheets(sheet1).[c1] - 1 ' (this is where i put the # of scenarios / sheets (-1 is used as i want the array to start from 0))
a = 0
Dim Scenarios_array, dimension_array() As Variant
ReDim Scenarios_array(0 To scenarios_number) '(resize array to match the #'s of scenarios)
ReDim dimension_array(0 To a)
For a = 0 To scenarios_number
Scenarios_array(a) = Range("c8").Offset(a, 0).Value '(this is where my scenarios' names start within sheet1 -- using offset for the loop -- this is why i use -1 above as i want a to start @ 0)
ReDim Preserve dimension_array(0 To a) ' (expand dimension of 2nd array)
dimension_array(a) = Scenarios_array(a) ' (save the value in the second array, expaning its dimensions)
Next
MsgBox "Get Ready"
Sheets(dimension_array()).Select
ActiveWindow.SelectedSheets.Delete
End Sub希望这能有所帮助:)
https://stackoverflow.com/questions/17169208
复制相似问题