以下代碼顯示具有固定大小的數組,其中包含六個值。基於單元值的變量數組
我應該怎麼做才能讓其大小取決於單元格的值?例如,從1到10?
Dim MySlideArray As Variant
Dim MyRangeArray As Variant
'List of PPT Slides to Paste to
MySlideArray = Array(2, 3, 4, 5, 6, 7)
'List of Excel Ranges to Copy from. For now, assume that it's always 6 ranges
With tb.DataBodyRange
MyRangeArray = Array(Worksheets(.Cells(1, 1).Value).Range(.Cells(1, 2).Value), _
Worksheets(.Cells(2, 1).Value).Range(.Cells(2, 2).Value), _
Worksheets(.Cells(3, 1).Value).Range(.Cells(3, 2).Value), _
Worksheets(.Cells(4, 1).Value).Range(.Cells(4, 2).Value), _
Worksheets(.Cells(5, 1).Value).Range(.Cells(5, 2).Value), _
Worksheets(.Cells(6, 1).Value).Range(.Cells(6, 2).Value))
'Loop through Array data
For x = LBound(MySlideArray) To UBound(MySlideArray)
'Copy Excel Range
MyRangeArray(x).Copy
'Paste to PowerPoint and position
On Error Resume Next
Set shp = myPresentation.Slides(MySlideArray(x)).Shapes.PasteSpecial(DataType:=2) 'Excel 2007-2010
Set shp = PowerPointApp.ActiveWindow.Selection.ShapeRange 'Excel 2013
On Error GoTo 0]
你的意思'redim'和/或'REDIM preserve'? –
我試過了!但沒有解決。我使用了以下代碼:[code] Dim Max as INteger Max = Sheets(「Home」)。Range(「H1」)。Value ReDim MySlideArray(2 To Max)[code],但沒有解決。在另一條線,上述所有這些 –
通過'REDIM myslidearray(2到最大)遇到錯誤91'你說你想用'最大的陣列 - 2'插槽的2'lbound'和最大的'ubound'不數值爲2到最大的數組。因此,在你的代碼是myslidearray調用'(2)'myslidearray(最大值)不爲1的'lbound'和5 –