欢迎来到天天文库
浏览记录
ID:55665512
大小:71.00 KB
页数:2页
时间:2020-05-23
《Excel VbA 读取某个文件夹下所有文件的内容.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、ExcelVbA读取某个文件夹下所有文件的内容SubGetAFolderMoreWorkBooks()DimfPathAsString‘路径名DimfNameAsString‘文件名DimsNameAsString‘工作表名称DimcellRangeAsString‘单元格范围DimfNameCountAsInteger‘文件数目DimfNameList()AsString‘文件名列表DimrValueAsVariant‘某个单元格中的值DimjAsIntegerDimoldColAsInteger‘文件夹下表格的活动单元格Dim
2、newColAsInteger‘新生成表格的活动单元格j=1oldCol=11newCol=1fPath="C:DocumentsandSettingsUSERデスクトップcheck"sName="レビュー記録"fName=Dir(fPath&""&"*.xls")WhilefName<>""‘获取该文件夹下所有表格的名字fNameCount=fNameCount+1ReDimPreservefNameList(1TofNameCount)fNameList(fNameCount)=fNamefName=DirWendW
3、orkbooks.AddIffNameCount=0ThenExitSubrValue=1Forj=1TofNameCountoldCol=11rValue=1WhilerValue<>0oldRange="A"&oldCol&":P"&oldColnewRange="B"&newCol&":R"&newColCells(newCol,1).Formula=fNameList(j)'MsgBox"fNameList:"&fNameList(j)IfrValue<>0ThenWithActiveSheet.Range(newRang
4、e).FormulaArray="='"&fPath&"["&fNameList(j)&"]"&sName&"'!"&oldRange.Value=.ValueEndWithEndIfoldCol=oldCol+1newCol=newCol+1rValue=ExecuteExcel4Macro("'"&fPath&"["&fNameList(j)&"]"&sName&"'!"&Range("a"&oldCol).Range("A1").Address(,,xlR1C1))WendNextjEndSub
此文档下载收益归作者所有