excel 求批量合并csv文件的宏
展开全部
代码如下:
Sub test()
Dim wb As Workbook, mary, f As String, mPath As String
'数据环境初始化
If Workbooks.Count > 1 Then MsgBox "关闭其他工作簿后重试": Exit Sub
'设置路径
MsgBox "选择原始数据所在的文件夹!"
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.Show
If .SelectedItems.Count = 0 Then MsgBox "你放弃了操作!": Exit Sub
mPath = .SelectedItems(1)
End With
Application.ScreenUpdating = False
f = Dir(mPath & "\*.csv")
Do While f <> ""
Set wb = Workbooks.Open(mPath & "\" & f)
mary = wb.Worksheets(1).[a1].CurrentRegion
wb.Close 0
With ThisWorkbook.Worksheets(1)
mrow = Application.CountA(.Range("A:A")) + 1
.Cells(mrow, 1).Resize(UBound(mary, 1), UBound(mary, 2)) = mary
End With
f = Dir
Loop
Application.ScreenUpdating = True
MsgBox "处理完成!"
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询