vba遍历文件夹的三种方法(the three methods of vba traversal folder)

vba遍历文件夹的三种方法(the three methods of vba traversal folder)

ID:9297668

大小:27.00 KB

页数:8页

时间:2018-04-27

vba遍历文件夹的三种方法(the three methods of vba traversal folder)_第1页
vba遍历文件夹的三种方法(the three methods of vba traversal folder)_第2页
vba遍历文件夹的三种方法(the three methods of vba traversal folder)_第3页
vba遍历文件夹的三种方法(the three methods of vba traversal folder)_第4页
vba遍历文件夹的三种方法(the three methods of vba traversal folder)_第5页
vba遍历文件夹的三种方法(the three methods of vba traversal folder)_第6页
vba遍历文件夹的三种方法(the three methods of vba traversal folder)_第7页
vba遍历文件夹的三种方法(the three methods of vba traversal folder)_第8页
资源描述:

《vba遍历文件夹的三种方法(the three methods of vba traversal folder)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、vba遍历文件夹的三种方法(ThethreemethodsofVBAtraversalfolder)TherearethreekindsofcommonlyusedVBAfoldertraversalmethod,thethreemethods,FileSearchisnotsuitableforthe2007and2010versions,andthespeedisslow,therecursivemethodisslow.OnlybyDIRcyclicmethod,fastspeed.Hereisthecodeofthethreemetho

2、d:1,FileSearchSub(test3)DimWBAsWorkbookDimIAsLongDimtT=TimerWithApplication.FileSearch'fileserchobjectcalled.NewSearch'tostartanewsearch.LookIn=ThisWorkbook.path'setsearchpath.SearchSubFolders=True'searchincludesallsubfoldersinthefolderspecifiedbytheLookInpropertySetthesearc

3、hfiletype.Filename="*.xls"'.FileType=msoFileTypeExcelWorkbooksIf(.Execute)>0Then'ifyoufindthefileForI=1To.FoundFiles.Count'OnErrorResumeNextCells(I,1)=.FoundFiles(I')tofindthedocumentsplacedinthecellNextIElseMsgBox"filenotfound"EndIfEndWithMsgBoxTimer-tEndSub2,therecursiveme

4、thodSub(Test)DimiPathAsString,IAsLongDimtT=TimerWithApplication.FileDialog(msoFileDialogFolderPicker).Title="selectasearchfolder"If.ShowThenIPath=.SelectedItems(1)EndIfEndWithIfiPath="False"OrLen(iPath)=0ThenExitSubI=1CallGetFolderFile(iPath,I)MsgBoxTimer-tMsgBox"filenamelin

5、kforcompletion."VbOKOnly,"that"EndSubPrivateSubGetFolderFile(ByValnPathAsStringByRefiCountAsLong)DimiFileSys'DimiFileAsFiles,gFileAsFile'DimiFolderAsFolder,sFolderAsFolders,nFolderAsFolderSetiFileSys=CreateObject("Scripting.FileSystemObject")SetiFolder=iFileSys.GetFolder(nPa

6、th)SetsFolder=iFolder.SubFoldersSetiFile=iFolder.FilesWithActiveSheetForEachgFileIniFile.Hyperlinks.Addanchor:=.Cells'(iCount,1),Address:=gFile.path,TextToDisplay:=gFile.NameICount=iCount+1NextEndWith'recursivetraversalofallsubfoldersForEachnFolderInsFolderCallGetFolderFile(

7、nFolder.path,iCount)NextEndSub3,thedircirculationmethodSub(Test)'doubledictionary,inordertoimprovethespeedDimMyName,Dic,Did,I,t,F,TT,MyFileName'OnErrorResumeNextSetobjShell=CreateObject("Shell.Application")SetobjShell.BrowseForFolder(objFolder=0,selectfolder,0,0)IfNotobjFold

8、erIsNothingThenLJ=objFolder.self.path&""SetobjFolder=NothingSetobjShell=No

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。