2016-09-22 74 views

回答

0

我假設你的意思是Excel工作簿,在每幾個工作表結合各自的所有工作表EXCEL導入一個Excel升序排列?如果是這種情況,請右鍵單擊要複製到新目標的選項卡,單擊「移動或複製...」並按照說明覆制到新的圖書。如果要將工作表保留在其原始位置以及製作副本,請務必選中「創建副本」框。

要清楚,您可以命名這個新的工作簿並將其他標籤移動或複製到它。

+1

你可以記錄我概述,如果你想要一個非VBA的解決方案中的步驟(我以爲這,出於某種原因),成宏,和操作同各一次。不過,我不得不承認我更喜歡Pav.s的方式:) – Zephyr

0

這應該做你所需要的,它可以讓你選擇你的文件夾,然後遍歷其中的所有文件,並將這些工作簿中的所有工作表合併到一個保存在同一目錄中的工作表中。不排序雖然,但你可以find multiple ready macros做到這一點,所以只需運行一個結果或粘貼他們的內容之前我的wb2保存&關閉。

Sub MergeFilesWithoutSpaces() 
Dim fldr As FileDialog 
Dim path As String 

'pick folder 
Set fldr = Application.FileDialog(msoFileDialogFolderPicker) 
With fldr 
    .Title = "Select a Folder" 
    .AllowMultiSelect = False 
    .InitialFileName = strPath 
    If .Show <> -1 Then Exit Sub 
    path = .SelectedItems(1) 
End With 

'create new workbook to store results and rename its sheet 
With Application 
    .EnableEvents = False 
    .ScreenUpdating = False 
    .SheetsInNewWorkbook = 1 
End With 
Set wb2 = Workbooks.Add 
wb2.Worksheets(1).Name = "00Delete_Me" 

'fetch filename 
Filename = Dir(path & "\*.xls", vbNormal) 
'loop through all *XLS files 
If Len(Filename) = 0 Then Exit Sub 
Do Until Filename = vbNullString 
     Set Wkb = Workbooks.Open(Filename:=path & "\" & Filename) 
     'copy each worksheet 
     For Each Sh In Wkb.Sheets 
      Sh.Copy After:=wb2.Sheets(wb2.Sheets.Count) 
     Next Sh 

     Wkb.Close False 
    Filename = Dir() 
Loop 
'delete the initial sheet and save result as "combined" workbook in same directory 
Application.DisplayAlerts = False 
wb2.Sheets("00Delete_Me").Delete 
wb2.SaveAs Filename:=(path & "\combined"), FileFormat:=xlOpenXMLWorkbookMacroEnabled 
Application.DisplayAlerts = True 
'close combined 
wb2.Close 
End Sub