admin管理员组文章数量:1122796
I'm parsing folders & subfolders for certain files with text in them and getting the results returned, but I keep getting "error 380 could not set the list property". I Redimemd my confList array to match the File results but can't see what I'm missing. Any help is appreciated!
Sub searchConf(Folder)
Dim SubFolder
Dim File
Dim confList()
Dim searchFullName As String
Dim i As Integer
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
i = 0
searchFullName = dwgText1.Value
For Each SubFolder In Folder.SubFolders
searchConf SubFolder
If SubFolder.Name Like searchFullName Then
i = i + 1
ReDim confList(1 To SubFolder.Files.Count, 1 To 3)
For Each File In SubFolder.Files
confList(i, 1) = File.Name
confList(i, 2) = FSO.GetExtensionName(LCase(File))
confList(i, 3) = File.path
Next
End If
Next
With list2
.Clear
.ColumnCount = 2
.ColumnWidths = "146;20"
.List = confList
End With
If list2.List(0) = "" Then
With list2
.Clear
.AddItem "NO FILES FOUND"
End With
End If
End Sub
The above Sub is called from:
Sub getConf()
Dim FileSystem As Object
Dim dataSplit() As String
Dim firstFolder, searchFullName As String
searchFullName = dwgText1.Value
dataSplit = Split(searchFullName, "-")
firstFolder = dataSplit(0)
folderName = folderName & "\" & firstFolder
Set FileSystem = CreateObject("Scripting.FileSystemObject")
searchConf FileSystem.GetFolder(folderName)
End Sub
I tried what you suggested but still getting the "308 error, could not set the list property". I confirmed the file count in the folder and that they were results from the for loop:
If Folder.Files.Count <> 0 Then
ReDim confList(1 To Folder.Files.Count, 1 To 3)
End If
For Each SubFolder In Folder.SubFolders
searchConf SubFolder
If SubFolder.Name Like searchFullName Then
Debug.Print SubFolder.Files.Count
ReDim confList(1 To SubFolder.Files.Count, 1 To 3)
i = i + 1
For Each File In SubFolder.Files
confList(i, 1) = File.Name
confList(i, 2) = FSO.GetExtensionName(LCase(File))
confList(i, 3) = File.path
Next
End If
Next
With list2
.Clear
.ColumnCount = 2
.ColumnWidths = "146;20"
.List = confList
End With
It generates the error at the ".List = confList" line. Am I not calling the array correctly there or is the problem with the array itself?
本文标签: vbaRedim Array for ListBoxStack Overflow
版权声明:本文标题:vba - Redim Array for ListBox - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736306894a1933120.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论