美文网首页
VBA 批量处理EXCEL文件

VBA 批量处理EXCEL文件

作者: qhqbcx | 来源:发表于2017-09-07 11:46 被阅读0次

Sub wb()
Dim writeFile As Workbook
Dim index As Integer

Set writeFile = Workbooks.Open("C:\Users\Administrator\Desktop\123.xlsx")
index = 1

myPath = "C:\Users\Administrator\Desktop\Test"
myfile = Dir(myPath & "*.xlsx")
Do Until Len(myfile) = 0

Dim tempFile As Workbook
Set tempFile = Workbooks.Open(myPath & myfile)

writeFile.Sheets(1).Cells(index, 1).Value = tempFile.Sheets(1).Cells(1, 1).Value
writeFile.Sheets(1).Cells(index, 2).Value = tempFile.Sheets(1).Cells(1, 2).Value
writeFile.Sheets(1).Cells(index, 3).Value = tempFile.Sheets(1).Cells(1, 1).Value * tempFile.Sheets(1).Cells(1, 2).Value

tempFile.Close savechanges:=True

myfile = Dir
index = index + 1

Loop

writeFile.Close savechanges:=True

End Sub

相关文章

网友评论

      本文标题:VBA 批量处理EXCEL文件

      本文链接:https://www.haomeiwen.com/subject/ohkodxtx.html