The first worksheet multiple Excel files (Sheet)

The first function is to achieve a worksheet multiple Excel files (Sheet) merged into a plurality of sheets in the Excel file, and the name of the new Excel worksheet is equal to the original file name.

Development environment Excel2007, Excel2003 but should also be able, Excel2000 can not seem to use.

Code is as follows:

'Function: merging a plurality of the workbook sheet to a first plurality of sheets of a workbook, a new sheet is equal to the name of the original name of the workbook

The new excel table --- new bookmark sheet1-- right-click View Code - copy the code into the run --- - Select Merge table - OK
Sub Books2Sheets ()
    'custom dialog variable
    Dim fd of As FileDialog
    the Set the Application fd = .FileDialog (msoFileDialogFilePicker)

    'Create a new workbook
    Dim newwb the workbook of As
    the Set newwb = the Workbooks.Add

    With FD
        the If the Then the .Show = -1
            ' define a single file variable
            Dim vrtSelectedItem of As the Variant

            'defined loop variable
            Dim of As Integer I
            I =. 1

            ' Fast start
            the For Each vrtSelectedItem the In .SelectedItems
                ' are combined to open a workbook
                Dim tempwb the workbook of As
                the Set tempwb the Workbooks.Open = (vrtSelectedItem)

                'Copy Sheet
                tempwb.Worksheets (1) .Copy the Before: = newwb.Worksheets (i)

                ' the new workbook worksheet name to be copied workbook file name, here applied to xls file, namely the Excel97-2003 file, if the Excel2007, need to change XLSX
                newwb.Worksheets (I) .Name = VBA.Replace (tempwb.Name, "* .xls", "")

                'are combined to close the workbook
                tempwb.Close the SaveChanges: = False

                I = +. 1 I
            the Next vrtSelectedItem
        End the If
    End With

    the Set FD = Nothing
End Sub
after the completion of the merger table modify the name of each sheet

Note: There is no consolidated up table, in the table to add a new sheet empty table - Hold down the table name and then be copied to move past the summary table

 

How to quickly merge multiple single sheet of excel table work page

1. First create a new worksheet in most previous page.

2. In the new sheet table "right" and find "View Code" and see the macro computing interface.

3. To see the macro computing interface, we just need to copy the following code into the code below ---- Click to Run

Sub merge all the current sheet in the workbook ()

Application.ScreenUpdating = False

For j = 1 To Sheets.Count

   If Sheets(j).Name <> ActiveSheet.Name Then

       X = Range("A65536").End(xlUp).Row + 1

       Sheets(j).UsedRange.Copy Cells(X, 1)

   End If

Next

Range("B1").Select

Application.ScreenUpdating = True

MsgBox "all the current worksheet in the workbook has completed the merger!", VbInformation, "prompt"

End Sub

Guess you like

Origin www.cnblogs.com/medik/p/11093738.html