我从不没有VBA脚本或宏。
但是我需要将很多excel文档粘贴到一个文档中。所以我想知道如何实现以下目标(或前进的方向):
我需要复制一个包含x行和y列的表,但是有很多空行。并且很多行被合并。我需要将其复制到另一个文件并取消合并行,然后将内容复制到所有合并的列。
有多个这样的文件,需要放入一个文件中。每个文件有不同数量的纸张。
如果仍然存在任何问题,我可以创建一个宏以仅复制和粘贴非空列并取消合并合并的列,并在所有合并的行之间具有相同的数据?
答案 0 :(得分:0)
这是部分答案,不涉及对单张纸的处理。它确实为您提供了一个框架。
Sub Process_Workbooks()
'Process a Collection of workbooks
Dim arrPathandFile, FilePointer As Long
Dim strPathAndFile As String
Dim bkSource As Workbook, shInput As Worksheet
Dim bkDestination As Workbook, shResult As Worksheet
Dim myPath, PathandFile As String
arrPathandFile = Application.GetOpenFilename("Audit Files (*.xls*), *.xlsx, All Files (*.*), *.*", , "Select Workbooks to process", "", True)
' user cancels file selection
If Not IsArray(arrPathandFile) Then Exit Sub
'Create a place to put the results
Set bkDestination = Workbooks.Add
'For each file in the collectin
For FilePointer = 1 To UBound(arrPathandFile)
strPathAndFile = arrPathandFile(FilePointer)
'Open the workbook
Set bkSource = Workbooks.Open(strPathAndFile)
'process each worksheet
For Each shInput In bkSource.Sheets
Set shResult = bkDestination.Sheets.Add
shResult.Name = shInput.Name & "(" & FilePointer & ")"
'figure out the source range to copy
shInput.Range("A1:Z900").Copy Destination:=shResult.Range("A1")
'now do stuff to the sheet in the destination.
Call Do_Stuff_To_sheets(shInput)
'repeat for each sheet in the workbook
Next shInput
bkSource.Close
'repeat for each workbook selected
Next FilePointer
'save the results
bkDestination.SaveAs myPath & "NewFilename.xlsx"
End Sub
Private Sub Do_Stuff_To_sheets(mySheet As Worksheet)
'process each sheet to unmerge and defrag columns
End Sub