1、Excel VbA 读取某个文件夹下所有文件的内容Sub GetAFolderMoreWorkBooks()Dim fPath As String 路径名Dim fName As String 文件名Dim sName As String 工作表名称Dim cellRange As String 单元格范围Dim fNameCount As Integer 文件数目Dim fNameList() As String 文件名列表Dim rValue As Variant 某个单元格中的值Dim j As IntegerDim oldCol As Integer 文件夹下表格的活动单元格Dim n
2、ewCol As Integer 新生成表格的活动单元格j = 1oldCol = 11newCol = 1fPath = “C:Documents and SettingsUSERcheck“sName = “記録“fName = Dir(fPath & “ & “*.xls“)While fName 0oldRange = “A“ & oldCol & “:P“ & oldColnewRange = “B“ & newCol & “:R“ & newColCells(newCol, 1).Formula = fNameList(j)MsgBox “fNameList:“ & fNameLi
3、st(j)If rValue 0 ThenWith ActiveSheet.Range(newRange).FormulaArray = “=“ & fPath & “ & fNameList(j) & “ & sName & “!“ & oldRange.Value = .ValueEnd WithEnd IfoldCol = oldCol + 1newCol = newCol + 1rValue = ExecuteExcel4Macro(“ & fPath & “ & fNameList(j) & “ & sName & “!“ & Range(“a“ & oldCol).Range(“A1“).Address(, , xlR1C1)WendNext jEnd Sub