わからないこと
エクセルVBAで以下のコードを実行するとout of boundsなエラーが出ます。。
vba
1Sub FileSearch(Path As String) 2 Dim FSO As Object 3 Dim Folder As Variant 4 5 '' ディレクトリパスを格納する為の配列 6 Dim aryPaths() As String 7 '' 配列の要素 8 Dim index As Single 9 10 index = 0 11 12 Set FSO = CreateObject("Scripting.FileSystemObject") 13 For Each Folder In FSO.GetFolder(Path).SubFolders 14 Call FileSearch(Folder.Path) 15 Next Folder 16 For Each File In FSO.GetFolder(Path).Files 17 Debug.Print File.Path '←この結果は期待値通り。結果は10件。 18 ReDim Preserve aryPaths(index) 19 aryPaths(index) = File.Path 20 index = index + 1 21 Next File 22 23Debug.Print aryPaths(0) '※ここでエラー※ 24 '実行時エラー '9'; 25 'インデックスが有効な範囲にありません 26End Sub 27```’ 28 29上記で「Debug.Print aryPaths(0)」というコードでエラーになります。。 30要素数は十分なのになぜ、、 31 32と、どはまりしております。。 33きっと、そんなこと、、という内容とは思いますが解決できず困っています。 34原因を教えてもらえませんでしょうか。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/15 02:28