При программировании вы не строите массив, этот большой человек, никогда.
либо хранить каждый многострочный-нить внутри клетки, и в конце концов вы Buid массив так:
option Explicit
Sub ArrayBuild()
Dim Filenames() 'as variant , and yes i presume when using multi files, the variable name should have an "s"
With Thisworkbook.sheets("temp") 'or other name of sheet
Max = .cells(.rows.count,1).end(xlup).row '=max number of rows in column 1
Filenames = .range(.cells(1,1) , .cells(Max,1)).value2 ' this example uses a one column range from a1 to a[max] , but you could also use a multi column by changing the second .cells to `.cells(Max, ColMax)`
end with
'do stuff
erase Filenames 'free memory
End Sub
Другим способом является создание массива, как вы строите дом, добавив один кирпич в то время, как это:
Dim Filenames() as string 'this time you can declare as string, but not in the previous example
Dim i& 'counter
For i=1 to Max 'same max as in previous example, adapt code plz...
redim Preserve Filenames (1 to ubound(filenames)+1) 'this is an example for unknown size array wich grows, but in your case you know the size (here Max, so you could declare it `Dim Filenames (1 to Max)` from the start, just wanted to show every option here.
Filenames(i) = Cells (i,1).value2 'for example, but can be anything else. Also i'm beeing lazy and did not reference the cell to its sheet, wich i'd never do in actual coding...
next i
EDIT я сделал перечитайте свой вопрос, и это еще проще (в основном потому, что вы в bracets опущен в вашем посте и исправить его в качестве комментария ...), используйте user3598756 's code plz. Я думал, что File1
является переменной, когда она должна быть записана как "File1"
.
EDIT 2 зачем нужно строить и массивы, где Filename (x) = «Filex»? вы знаете результат заранее
являются 'file1',' file2' ..., определенные как 'String', или они просто текст? –
Просьба заполнить полный код, чтобы узнать, где произошла ошибка компиляции. – Parfait
избежать новых строк с помощью '_' или сохранить имена файлов на скрытом листе и прочитать их в виде массива? http://stackoverflow.com/questions/8303821/if-statement-with-multiple-lines – Orphid