打开对话框选择多个文件进行汇总
1、打开对话框选择文件,可以多选
2、将选中的文件进行循环,逐一打开将其中的数据汇总到总表里,然后关闭这个文件
3. 将copy来的数据在总表里向下增加
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | Sub 导入多工作簿() Dim oWb As Object : Set oWb = ThisWorkbook Dim intFilesCount As Integer Dim strFilePath As String Dim rs Application.ScreenUpdating = False '屏幕闪烁关闭 Set sh = ThisWorkbook.Worksheets( "学籍" ) sh.UsedRange.Offset(1) = Empty Dim oFd As Object Set oFd = Application.FileDialog(msoFileDialogFilePicker) With oFd .AllowMultiSelect = True .Filters.Add "Excel文档" , "*.csv; *.csv; *.csv" , 1 .FilterIndex = 1 .InitialFileName = oWb.Path .InitialView = msoFileDialogViewDetails If .Show = -1 Then intFilesCount = .SelectedItems.Count For i = 1 To intFilesCount strFilePath = .SelectedItems(i) Set Wb = Workbooks.Open(strFilePath) ar = Wb.Worksheets(1).[a1].CurrentRegion.Offset(1) rs = sh.[a65536]. End (xlUp).Row + 1 sh.Cells(rs, 1).Resize(UBound(ar), UBound(ar, 2)) = ar Wb.Close False Next i Else Exit Sub End If End With Application.ScreenUpdating = True '屏幕闪烁打开 End Sub |
使用vba将其他数据导出到excel
1 2 3 4 5 6 7 | Dim oXl As Object : Set oXl = CreateObject( "excel.application" ): oXl.Visible = True '打开excel并使得可见 Dim oBk As Object : Set oBk = oXl.Workbooks.Add '打开一个工作簿 Dim oSht As Object : Set oSht = oBk.Worksheets.Add '打开一个工作表 oSht.Range( "a1" ).Resize(UBound(arr, 1) - LBound(arr, 1) + 1, UBound(arr, 2) - LBound(arr, 2) + 1) = arr '小标从0开始 oBk.Save '保存工作簿 oBk.Close '关闭工作簿 oXl.Quit '退出excel程序 |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现