Excel文件合并(基于宏)
来源:互联网 发布:太极越狱for mac 编辑:程序博客网 时间:2024/05/22 06:51
Private Function SelectDir() As String
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
With fd '用户按下的是操作按钮 (-1) 还是取消按钮 (0)
If .Show = -1 Then
SelectDir = .SelectedItems(1) & "\"
End If
End With
Set fd = Nothing
End Function
Sub SearchFile()
Dim MyFolder, MyFile As String
Dim i As Integer
MyFolder = SelectDir()
Sheets("文件列表").Cells(1, 2) = MyFolder
i = 1
MyFile = Dir(MyFolder)
Do While MyFile <> ""
Sheets("文件列表").Cells(i, 1) = MyFile
MyFile = Dir
i = i + 1
Loop
End Sub
Sub CombineSheets()
Dim MyFolder, MyFile, CurBook As String
Dim RowCount, FileCount, i As Integer
With Sheets("文件列表")
MyFolder = .Range("B1").Value
FileCount = .[A65535].End(xlUp).Row
.Range("B:B").ClearContents
.Range("B1").Value = "合并出错"
End With
CurBook = ActiveWorkbook.Name
With Application
.DisplayAlerts = False
.ScreenUpdating = False
End With
On Error GoTo ErrOpen
For i = 1 To FileCount
With Workbooks(CurBook)
'RowCount = .Sheets("合并内容").[A65535].End(xlUp).Row
'MyFile = .Sheets("文件列表").Cells(i, 1)
'Application.Workbooks.Open (MyFolder & MyFile)
'Workbooks(MyFile).Sheets(1).UsedRange.Copy
'.Sheets("合并内容").Cells(RowCount + 1, 1).PasteSpecial
'.Sheets("合并内容").Rows(RowCount + 1).EntireRow.Delete
'Application.Workbooks(MyFile).Close savechanges:=False
'.Sheets("文件列表").Cells(i, 2) = "合并完成"
MyFile = .Sheets("文件列表").Cells(i, 1)
'MsgBox i, vbInformation, "hcccc"
Application.Workbooks.Open (MyFolder & MyFile)
'MsgBox i, vbInformation, "haaaa"
Workbooks(MyFile).Sheets(1).Columns("B:B").Copy
' MsgBox i, vbInformation, "hbbbb"
.Sheets("合并内容").Columns(i).PasteSpecial '黏贴
Application.Workbooks(MyFile).Close savechanges:=False
.Sheets("文件列表").Cells(i, 2) = "合并完成"
End With
Next i
ErrOpen:
With Application
.DisplayAlerts = True
.ScreenUpdating = True
End With
End Sub
Sub ClearFileList()
With Sheets("文件列表")
.Range("A:A").ClearContents
.Range("B:B").ClearContents
End With
End Sub
Sub ClearDetail()
Sheets("合并内容").Cells.ClearContents
End Sub
- Excel文件合并(基于宏)
- 合并excel 宏文件
- VBA EXCEL 文件合并
- excel 合并文件 vba
- VBA excel文件合并
- 合并多个Excel文件
- Excel 合并多个文件
- Excel的二次开发实例:合并Excel文件
- java 基于poi 写入excel 合并单元格
- 利用 VBA 批量合并 EXCEL 文件
- 使用VBA合并多个Excel文件
- 合并多个Excel文件工具
- 合并多个excel文件内容
- java读写Excel文件、合并单元格
- excel 多个文件合并,字段相同
- 如何将多个excel文件合并成一个
- 使用Python横向合并excel文件
- excel sheet合并 宏初学
- Java中的ThreadUtil
- CAS 配置使用方法
- spring组件扫描<context:component-scan/>使用详解
- Hyper-Threading , dual-processor and double CPU
- ubuntu 10.10 + Bochs 2.2.6 安装中出现的一些问题
- Excel文件合并(基于宏)
- C++虚继承的作用
- 线程2
- Q&A:苹果公司的劣势、缺点是什么?
- Agile Scrum
- 从ERP应用谈对BOM的理解
- 随笔
- 外排序时间估计和趟数计算的理解
- u-boot的流程、主要的数据结构、内存分配