2010-06-28 142 views
4

這裏是我的代碼:收藏最大尺寸

Sub isdofsodjisf48023jroi23f984444444jiodfiosj12348023jroi23f98() 


Dim colFiles As New Collection 
    RecursiveDir colFiles, "C:\Documents and Settings\Alex Gordon\Desktop\testing\files\", "*.xls", True 

    Dim vFile As Variant 
    For Each vFile In colFiles 
     Call writeincells(vFile) 
    Next vFile 

End Sub 



Public Function RecursiveDir(colFiles As Collection, _ 
          strFolder As String, _ 
          strFileSpec As String, _ 
          bIncludeSubfolders As Boolean) 

    Dim strTemp As String 
    Dim colFolders As New Collection 
    Dim vFolderName As Variant 

    'Add files in strFolder matching strFileSpec to colFiles 
    strFolder = TrailingSlash(strFolder) 
    strTemp = Dir(strFolder & strFileSpec) 
    Do While strTemp <> vbNullString 
     colFiles.Add strFolder & strTemp 
     strTemp = Dir 
    Loop 

    If bIncludeSubfolders Then 
     'Fill colFolders with list of subdirectories of strFolder 
     strTemp = Dir(strFolder, vbDirectory) 
     Do While strTemp <> vbNullString 
      If (strTemp <> ".") And (strTemp <> "..") Then 
       If (GetAttr(strFolder & strTemp) And vbDirectory) <> 0 Then 
        colFolders.Add strTemp 
       End If 
      End If 
      strTemp = Dir 
     Loop 

     'Call RecursiveDir for each subfolder in colFolders 
     For Each vFolderName In colFolders 
      Call RecursiveDir(colFiles, strFolder & vFolderName, strFileSpec, True) 
     Next vFolderName 
    End If 

End Function 


Public Function TrailingSlash(strFolder As String) As String 
    If Len(strFolder) > 0 Then 
     If Right(strFolder, 1) = "\" Then 
      TrailingSlash = strFolder 
     Else 
      TrailingSlash = strFolder & "\" 
     End If 
    End If 
End Function 

我與文件名的目錄結構列表填充一個集合。

我有2000個文件,但目前只有256返回有誰知道,如果有,它不會晃過最大值是多少?

如果是的話,可以請你提出一個更好的實現代碼宏以便它捕獲所有的2000個文件?

+0

您的代碼工作完全正常,我與成千上萬的文件。你確定你有權限訪問該文件夾嗎? – 2010-06-28 22:38:58

+2

對不起,我不得不問。你是怎麼想出這個程序名稱的? – 2010-06-29 14:40:23

+4

請不要問這樣的難題 – 2010-06-29 16:44:55

回答

14

的代碼在Excel 2007工作OK也許正在發生的事情是,你嘗試觀看在調試模式下集合。調試器只顯示前256個項目。