Note: The other languages of the website are Google-translated. Back to English
Logáil isteach  \/ 
x
or
x
Cláraigh  \/ 
x

or

Conas iliomad leabhar oibre a chur le chéile i máistirleabhar oibre amháin in Excel?

An raibh tú riamh i bhfostú nuair a chaithfidh tú iliomad leabhar oibre a chur le chéile i máistirleabhar oibre in Excel? Is é an rud is uafásaí ná go bhfuil iliomad bileoga oibre sna leabhair oibre a chaithfidh tú a chur le chéile. Agus conas na bileoga oibre sonraithe de iliomad leabhar oibre a chomhcheangal in aon leabhar oibre amháin? Taispeánann an rang teagaisc seo roinnt modhanna úsáideacha chun cabhrú leat na fadhbanna a réiteach céim ar chéim.


Comhcheangail iliomad leabhar oibre Isteach i leabhar oibre amháin le feidhm Bog nó Cóipeáil

Mura bhfuil ach cúpla leabhar oibre le chéile, is féidir leat an t-ordú Bog nó Cóipeáil a úsáid chun bileoga oibre a bhogadh nó a chóipeáil de láimh ón mbunleabhar oibre go dtí an máistirleabhar oibre.

1. Oscail na leabhair oibre a chumascfaidh tú le máistirleabhar oibre.

2. Roghnaigh na bileoga oibre sa bhunleabhar oibre a bhogfaidh tú nó a chóipeáilfidh tú chuig an máistirleabhar oibre.

Nótaí:

1). Is féidir leat iliomad bileoga oibre neamh-in aice láimhe a roghnú leis an Ctrl eochair agus cliceáil na cluaisíní bileog ceann ar cheann.

2). Chun iliomad bileoga oibre cóngaracha a roghnú, cliceáil ar an gcéad chluaisín le do thoil, coinnigh an Shift eochair, agus ansin cliceáil ar an táb deireanach bileog chun iad uile a roghnú.

3). Is féidir leat cliceáil ar dheis ar aon chluaisín bileog, cliceáil ar Roghnaigh Gach Bileog ón roghchlár comhthéacs chun gach bileog oibre sa leabhar oibre a roghnú ag an am céanna.

3. Tar éis duit na bileoga oibre riachtanacha a roghnú, cliceáil ar dheis ar an táb bileog, agus ansin cliceáil Bog nó Cóipeáil ón roghchlár comhthéacs. Féach an pictiúr:

4. Ansin an Bog nó Cóipeáil pops dialóg suas, sa A chur in áirithe anuas, roghnaigh an máistirleabhar oibre a bhogfaidh tú nó cóipeálfaidh tú bileoga oibre ann. Roghnaigh bogadh chun deiridh sa Roimh an mbileog bosca, seiceáil an Cruthaigh cóip bosca, agus ar deireadh cliceáil ar an OK cnaipe.

Ansin is féidir leat bileoga oibre a fheiceáil in dhá leabhar oibre le chéile i gceann amháin. Déan na céimeanna thuas arís le do thoil chun bileoga oibre a aistriú ó leabhair oibre eile go dtí an máistirleabhar oibre.


Comhcheangail iliomad leabhar oibre nó bileoga sonraithe leabhar oibre le máistirleabhar oibre le VBA

Má tá iliomad leabhar oibre ann is gá a chumasc i gceann amháin, is féidir leat na cóid VBA seo a leanas a chur i bhfeidhm chun é a bhaint amach go tapa. Déan mar a leanas le do thoil.

1. Cuir gach leabhar oibre is mian leat a chur le chéile i gceann amháin faoin eolaire céanna.

2. Seoladh comhad Excel (beidh an leabhar oibre seo mar an máistirleabhar oibre).

3. Brúigh an Eile + F11 eochracha a oscailt Microsoft Visual Basic d’iarratais fuinneog. Sa Microsoft Visual Basic d’iarratais fuinneog, cliceáil Ionsáigh > Modúil, ansin cóipeáil thíos cód VBA isteach i bhfuinneog an Mhodúil.

Cód VBA 1: Comhcheangail iliomad leabhar oibre Excel i gceann amháin

Sub GetSheets()
'Updated by Extendoffice 2019/2/20
Path = "C:\Users\dt\Desktop\dt kte\"
Filename = Dir(Path & "*.xlsx")
  Do While Filename <> ""
  Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
     For Each Sheet In ActiveWorkbook.Sheets
     Sheet.Copy After:=ThisWorkbook.Sheets(1)
  Next Sheet
     Workbooks(Filename).Close
     Filename = Dir()
  Loop
End Sub
	

Nótaí:

1. Coinneoidh an cód VBA thuas ainmneacha bileoga na mbunleabhar oibre tar éis iad a chumasc.

2. Más mian leat idirdhealú a dhéanamh ar na bileoga oibre sa mháistirleabhar oibre as ar tháinig tú, déan an cód VBA 2 thíos a chur i bhfeidhm.

3. Mura dteastaíonn uait ach bileoga oibre sonraithe de na leabhair oibre a chomhcheangal i máistirleabhar oibre, is féidir leis an gcód 3 VBA thíos cabhrú leat.

I gcóid VBA, “C: \ Úsáideoirí \ DT168 \ Deisce \ KTE \"Is é cosán an fhillteáin. I gcód VBA 3, "Bileog1, Bileog3"is é seo bileoga oibre sonraithe na leabhar oibre a chomhcheanglóidh tú le máistirleabhar oibre. Is féidir leat iad a athrú bunaithe ar do chuid riachtanas.

Cód VBA 2: Cumaisc Leabhair Oibre i gceann amháin (ainmneofar gach bileog oibre le réimír a hainm comhaid bunaidh):

Sub MergeWorkbooks()
'Updated by Extendoffice 2019/2/20
Dim xStrPath As String
Dim xStrFName As String
Dim xWS As Worksheet
Dim xMWS As Worksheet
Dim xTWB As Workbook
Dim xStrAWBName As String
On Error Resume Next
xStrPath = "C:\Users\DT168\Desktop\KTE\"
xStrFName = Dir(xStrPath & "*.xlsx")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set xTWB = ThisWorkbook
Do While Len(xStrFName) > 0
    Workbooks.Open Filename:=xStrPath & xStrFName, ReadOnly:=True
    xStrAWBName = ActiveWorkbook.Name
    For Each xWS In ActiveWorkbook.Sheets
    xWS.Copy After:=xTWB.Sheets(xTWB.Sheets.Count)
    Set xMWS = xTWB.Sheets(xTWB.Sheets.Count)
    xMWS.Name = xStrAWBName & "(" & xMWS.Name & ")"
    Next xWS
    Workbooks(xStrAWBName).Close
    xStrFName = Dir()
Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub

Cód VBA 3: Bileoga oibre sonraithe de leabhair oibre a chumasc le máistirleabhar oibre:

Sub MergeSheets2()
'Updated by Extendoffice 2019/2/20
Dim xStrPath As String
Dim xStrFName As String
Dim xWS As Worksheet
Dim xMWS As Worksheet
Dim xTWB As Workbook
Dim xStrAWBName As String
Dim xI As Integer
On Error Resume Next

xStrPath = " C:\Users\DT168\Desktop\KTE\"
xStrName = "Sheet1,Sheet3"

xArr = Split(xStrName, ",")

Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set xTWB = ThisWorkbook
xStrFName = Dir(xStrPath & "*.xlsx")
Do While Len(xStrFName) > 0
Workbooks.Open Filename:=xStrPath & xStrFName, ReadOnly:=True
xStrAWBName = ActiveWorkbook.Name
For Each xWS In ActiveWorkbook.Sheets
For xI = 0 To UBound(xArr)
If xWS.Name = xArr(xI) Then
xWS.Copy After:=xTWB.Sheets(xTWB.Sheets.count)
Set xMWS = xTWB.Sheets(xTWB.Sheets.count)
xMWS.Name = xStrAWBName & "(" & xArr(xI) & ")"
Exit For
End If
Next xI
Next xWS
Workbooks(xStrAWBName).Close
xStrFName = Dir()
Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub

4. Brúigh an F5 eochair chun an cód a rith. Ansin cuirtear gach bileog oibre nó bileog oibre shonraithe de na leabhair oibre san fhillteán áirithe le chéile le máistirleabhar oibre ag an am céanna.


Comhcheangail go héasca iliomad leabhar oibre nó bileoga sonraithe leabhar oibre le leabhar oibre amháin

Ar ámharaí an tsaoil, tá an Chomhcheangail leabhar oibre fóntais de Kutools le haghaidh Excel déanann sé i bhfad níos éasca iliomad leabhar oibre a chumasc i gceann amháin. Feicfimid conas an fheidhm seo a chur ag obair chun iliomad leabhar oibre a chur le chéile.

Roimh iarratas a dhéanamh Kutools le haghaidh Excel, Le do thoil é a íoslódáil agus a shuiteáil ar dtús.

1. Cruthaigh leabhar oibre nua agus cliceáil Kutools Plus > Chomhcheangail. Ansin pops dialóg le cur i gcuimhne duit gur chóir gach leabhar oibre comhcheangailte a shábháil agus nach féidir an ghné a chur i bhfeidhm ar leabhair oibre faoi chosaint, cliceáil le do thoil OK cnaipe.

2. Sa Comhcheangail Bileoga Oibre draoi, roghnaigh Comhcheangail iliomad bileoga oibre ó leabhair oibre in aon leabhar oibre amháin rogha, agus ansin cliceáil ar an Ar Aghaidh cnaipe. Féach an pictiúr:

3. Sa Comhcheangail Bileoga Oibre - Céim 2 de 3 bosca dialóige, cliceáil an Cuir > Comhad or Fillteán chun na comhaid Excel a chur leis, cumascfaidh tú isteach i gceann amháin iad. Tar éis duit na comhaid Excel a chur leis, cliceáil an Críochnaigh cnaipe agus roghnaigh fillteán chun an máistirleabhar oibre a shábháil. Féach an pictiúr:

Anois déantar gach leabhar oibre a chumasc i gceann amháin.

I gcomparáid leis an dá mhodh thuas, Kutools le haghaidh Excel tá na buntáistí seo a leanas aige:

  • 1) Tá gach leabhar oibre agus bileog oibre liostaithe sa bhosca dialóige;
  • 2) Maidir leis na bileoga oibre is mian leat a eisiamh ó chumasc, ní gá ach iad a dhísheiceáil;
  • 3) Déantar bileoga oibre bán a eisiamh go huathoibríoch;
  • 4) Cuirfear ainm bunaidh an chomhaid mar réimír le hainm na bileoige tar éis é a chumasc;
  • Le haghaidh tuilleadh feidhmeanna den ghné seo, tabhair cuairt anseo.

  Más mian leat triail saor in aisce (30 lá) a bheith agat ar an bhfóntas seo, cliceáil le do thoil chun é a íoslódáil, agus ansin téigh chun an oibríocht a chur i bhfeidhm de réir na gcéimeanna thuas.


Kutools le haghaidh Excel - Cabhraíonn sé leat an obair a chríochnú i gcónaí roimh an am, Bíodh níos mó ama agat chun taitneamh a bhaint as an saol
An minic a bhíonn tú ag imirt teacht suas leis an obair, easpa ama le caitheamh ort féin agus ag do mhuintir?  Kutools le haghaidh Excel in ann cabhrú leat déileáil le puzail Excel 80% agus éifeachtúlacht oibre 80% a fheabhsú, níos mó ama a thabhairt duit aire a thabhairt don teaghlach agus taitneamh a bhaint as an saol.
300 uirlis chun cinn le haghaidh 1500 cás oibre, déan do phost an oiread sin níos éasca ná riamh.
Ní gá foirmlí agus cóid VBA a chur de ghlanmheabhair a thuilleadh, tabhair sosa d’inchinn as seo amach.
Is féidir oibríochtaí casta agus arís agus arís eile a phróiseáil aon-uaire i soicindí.
Laghdaigh na mílte oibríochtaí méarchláir & luch gach lá, slán a fhágáil le galair cheirde anois.
Bí i do shaineolaí Excel i gceann 3 nóiméad, cabhrú leat aitheantas tapa a fháil agus ardú céime pá a fháil.
110,000 duine an-éifeachtach agus 300+ rogha cuideachtaí a bhfuil cáil dhomhanda orthu.
Déan do $ 39.0 ar fiú níos mó ná $ 4000.0 oiliúint daoine eile.
Triail saor in aisce gné iomlán 30 lá. Ráthaíocht Airgead Ar Ais 60 Lá gan chúis.

Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Chris · 2 months ago
    Hello!  I need to merge multiple files into one, that are password protected.  All source files use the same password.  What changes are needed to the first VBA script to merge the files without having to enter the password each time?
  • To post as a guest, your comment is unpublished.
    Kedar Dahal · 6 months ago
    Hello any one can help me, I want to combine sheet 2 only from 5 different sheet, can you script for me.
  • To post as a guest, your comment is unpublished.
    venkatesh · 10 months ago
    hai sir i want know code for copying multiple sheets in one excel to multiple excels
  • To post as a guest, your comment is unpublished.
    venkatesh · 10 months ago
    hai sir i want know code for copying multiple sheets in one excel to multiple excels
  • To post as a guest, your comment is unpublished.
    noelle · 1 years ago
    how to use VBA code 1 to amend and make it runs to combine all the .xlsx files into one excel file and each excel spreedsheet tab in the combined excel file should be named as original file name.thanks
  • To post as a guest, your comment is unpublished.
    Steve · 1 years ago
    What part of VBA code 3 specifies the name of the worksheet to be copied?

  • To post as a guest, your comment is unpublished.
    Rajni bala · 1 years ago
    sir i want to compile different worksheets from different workbook into one master sheet
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Good day,
      I recommend the first option "Combine multiple worksheets from workbooks into one worksheet" of the Combine feature in Kutools for Excel to handle this work.
      You can open the below hyperlink for more details of this option:
      https://www.extendoffice.com/product/kutools-for-excel/excel-combine-worksheets-into-one.html#a1
  • To post as a guest, your comment is unpublished.
    Rangaswamy · 1 years ago
    Hi, While combining the worksheets from different workbooks, I want it to be paste special values. How to do that?
  • To post as a guest, your comment is unpublished.
    RameshPK · 1 years ago
    Hello Sir,
    When I run the VBA code 1, as per the instructions given. The script ran without any errors. but I could see in the master file
    1) each xls file from the directory got created 2 times in the master workbook.
    2) if master file name falls in between the other sheet names (ex: file1.xls, file2.xls, file3_master.xls, file4.xls ... ) then file4.xls is not being added into the file3_master.xls file.
    file1, file2 got created 2 times...

    Please help how to address this ?

    Thank you,
    Ramesh
  • To post as a guest, your comment is unpublished.
    Sippika Kwatra · 1 years ago
    In VBA 2 option my sheet names as Name.xlsx - Can we remove .xlsx?
  • To post as a guest, your comment is unpublished.
    Ai · 1 years ago
    hello, vba code 3 isn't worked with me. can anyone help me? i'm using excel 2016. the code hasn't error. but, it can't worked. thanks
  • To post as a guest, your comment is unpublished.
    ltrung · 2 years ago
    Hello, can anyone advise me please if it is possible to combine workbooks NOT into the one where I have(run) the button with VBA macro BUT to a completely different new workbook? So basically I would like to know if it is possible to create a macro in VBA that would create new workbook(file) with combined data from other workbooks? Would greatly appreciate your help! Thank you!
  • To post as a guest, your comment is unpublished.
    Gerdy · 2 years ago
    Say you want to combine workbooks by fives or twos or tens. So basically, if you have 50 workbooks and you want to combine them by fives, you'll have 10 workbooks, each having 5 workbooks worth of data by the end of it. How do you tweak this data?
  • To post as a guest, your comment is unpublished.
    shashank · 2 years ago
    VBA Code2 is working but the sheet names are "Consolidated"1,2 and so on not the original workbook names, How can I get the sheet names as original workbook names. Pls anyone help me..
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Good day,
      After applying the above VBA 2, the original worksheets' information (the workbook names) will be added to the corresponding worksheet names as prefix.
  • To post as a guest, your comment is unpublished.
    Treb · 2 years ago
    Tanx for this, it helps me a lot... looking forward for more help from you. God bless you always.
  • To post as a guest, your comment is unpublished.
    dezignextllc@gmail.com · 2 years ago
    I like using this technique better than using traditional "3D Formula" techniques in Excel.
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      I’m glad I could help ^_^
  • To post as a guest, your comment is unpublished.
    Jonel · 2 years ago
    Note: This VBA code can merge the entire workbooks into the master workbook, if you want to combine specified worksheets of the workbooks, this code will not work.

    Can we have the module for VBA that above scene will work,
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Hi Jonel,
      The following code can help you solve the problem. You need to replace folder path and "Sheet1, Sheet3" with the specified folder path and worksheets as you need.

      Sub MergeSheets2()
      Dim xStrPath As String
      Dim xStrFName As String
      Dim xWS As Worksheet
      Dim xMWS As Worksheet
      Dim xTWB As Workbook
      Dim xStrAWBName As String
      Dim xI As Integer
      On Error Resume Next

      xStrPath = " C:\Users\DT168\Desktop\KTE\"
      xStrName = "Sheet1,Sheet3"

      xArr = Split(xStrName, ",")

      Application.ScreenUpdating = False
      Application.DisplayAlerts = False
      Set xTWB = ThisWorkbook
      xStrFName = Dir(xStrPath & "*.xlsx")
      Do While Len(xStrFName) > 0
      Workbooks.Open Filename:=xStrPath & xStrFName, ReadOnly:=True
      xStrAWBName = ActiveWorkbook.Name
      For Each xWS In ActiveWorkbook.Sheets
      For xI = 0 To UBound(xArr)
      If xWS.Name = xArr(xI) Then
      xWS.Copy After:=xTWB.Sheets(xTWB.Sheets.count)
      Set xMWS = xTWB.Sheets(xTWB.Sheets.count)
      xMWS.Name = xStrAWBName & "(" & xArr(xI) & ")"
      Exit For
      End If
      Next xI
      Next xWS
      Workbooks(xStrAWBName).Close
      xStrFName = Dir()
      Loop
      Application.ScreenUpdating = True
      Application.DisplayAlerts = True

      End Sub
  • To post as a guest, your comment is unpublished.
    Chris · 3 years ago
    When I run this, each sheet in the new workbook is being named based off of the sheet names of the original document rather than the filenames. Any idea what I might be doing wrong?
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Hi Chris,
      If you want to distinguish which worksheets in the master workbook came from where after merging, please apply the below VBA code to solve the problem.

      Sub MergeWorkbooks()
      Dim xStrPath As String
      Dim xStrFName As String
      Dim xWS As Worksheet
      Dim xMWS As Worksheet
      Dim xTWB As Workbook
      Dim xStrAWBName As String
      On Error Resume Next
      xStrPath = "C:\Users\DT168\Desktop\KTE\"
      xStrFName = Dir(xStrPath & "*.xlsx")
      Application.ScreenUpdating = False
      Application.DisplayAlerts = False
      Set xTWB = ThisWorkbook
      Do While Len(xStrFName) > 0
      Workbooks.Open Filename:=xStrPath & xStrFName, ReadOnly:=True
      xStrAWBName = ActiveWorkbook.Name
      For Each xWS In ActiveWorkbook.Sheets
      xWS.Copy After:=xTWB.Sheets(xTWB.Sheets.Count)
      Set xMWS = xTWB.Sheets(xTWB.Sheets.Count)
      xMWS.Name = xStrAWBName & "(" & xMWS.Name & ")"
      Next xWS
      Workbooks(xStrAWBName).Close
      xStrFName = Dir()
      Loop
      Application.ScreenUpdating = True
      Application.DisplayAlerts = True
      End Sub
  • To post as a guest, your comment is unpublished.
    Owen · 3 years ago
    It didnt work for me then I realized my files are .xlsx, so added the missing "x" to the Filename line.
  • To post as a guest, your comment is unpublished.
    Justin · 3 years ago
    This worked for me but I had to make sure I have to put "\" at the end of my path. Initially, I didn't have it and it wouldn't work.
  • To post as a guest, your comment is unpublished.
    Simona Pandele · 3 years ago
    The VBA code isn't working for me. I have entered my path but is there anything else that I need to customize to make it run? I can't easily see what else I might need to enter.
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Good day,
      Please make sure you have put "\" at the end of your path. Thanks for your comment.
  • To post as a guest, your comment is unpublished.
    janu · 3 years ago
    code not worked can anyone help me
  • To post as a guest, your comment is unpublished.
    Daniela · 3 years ago
    Big thanks! It was just what I needed
  • To post as a guest, your comment is unpublished.
    Gavin · 3 years ago
    This doesn't seem to mention the easiest method (at least for a limited number of sheets): simply drag the tab at the bottom of each sheet to the new workbook.
  • To post as a guest, your comment is unpublished.
    Nahid · 3 years ago
    Hello All, please help me.

    I have one old worksheet list with their email address and one new worksheet, how can I merge this two list and take the duplicates and have the one with email address from duplicates
    • To post as a guest, your comment is unpublished.
      Muhammad · 3 years ago
      Use the remove duplicates option in Excel 2016

      https://support.office.com/en-us/article/Filter-for-unique-values-or-remove-duplicate-values-ccf664b0-81d6-449b-bbe1-8daaec1e83c2
  • To post as a guest, your comment is unpublished.
    Tanner Markley · 3 years ago
    Thank you for providing the VBA code!
  • To post as a guest, your comment is unpublished.
    · 4 years ago
    Hi everyone,

    First of all I have to tell that I have no experience with Macro (VBA Codes). However what I need is related to this. Maybe you guys could help me with it.

    I have a workbook and in this workbook there are 10 worksheets. The first 9 Sheets have the same order of the coloumns of titles and in these columns there are names, dates, percentages of Project Status, comments to Projects etc.. As I said the columns have the same order just the name of the worksheets (for different Teams in the Organisation) are different.

    In Addition to this I have to merge all the worksheets and have them in another sheet which is called "Übersicht" (Overview). However there is a different column in the sheet and it's between "Nr." and "Thema" columns (which are in A1 and A2 in all the 9 Sheets) and this different column called "Kategorie" (in A2 in Übersicht-Overwiev sheet). As this column is between These the order is like this "Nr. (A1), Kategorie (A2) and Thema (A3).....".So this category column (Kategorie) should be empty except this all the Information should be merged into this sheet. And also when there is a Change or update in any worksheet, the Information in "Übersicht" (Overview) sheet needs to update by itself. How can I do this?

    I hope I explained it well. Thanks a lot in advance!

    I wish you merry Christmas and a happy new year!

    oduff
  • To post as a guest, your comment is unpublished.
    Snow · 4 years ago
    Thank you for the VB code it has helped me with my job to make it easy.
  • To post as a guest, your comment is unpublished.
    James Gibson · 4 years ago
    When merging multiple Excel files, how can I get the merge routine to skip the first row on all but the first worksheet (so that only data are in the merged file, not variable names with each new Excel worksheet that gets added to the merged data set)?
  • To post as a guest, your comment is unpublished.
    adamwgrise@gmail.com · 4 years ago
    By the way, I'm using Excel 2016 and here's the code I have, which seems to work correctly:

    Sub mergeFiles()
    Dim numberOfFilesChosen, i As Integer
    Dim tempFileDialog As FileDialog
    Dim mainWorkbook, sourceWorkbook As Workbook
    Dim tempWorkSheet As Worksheet

    Set mainWorkbook = Application.ActiveWorkbook
    Set tempFileDialog = Application.FileDialog(msoFileDialogFilePicker)

    tempFileDialog.AllowMultiSelect = True

    numberOfFilesChosen = tempFileDialog.Show

    For i = 1 To tempFileDialog.SelectedItems.Count

    Workbooks.Open tempFileDialog.SelectedItems(i)

    Set sourceWorkbook = ActiveWorkbook

    For Each tempWorkSheet In sourceWorkbook.Worksheets
    tempWorkSheet.Copy after:=mainWorkbook.Sheets(mainWorkbook.Worksheets.Count)
    Next tempWorkSheet

    sourceWorkbook.Close
    Next i

    End Sub
  • To post as a guest, your comment is unpublished.
    adamwgrise@gmail.com · 4 years ago
    This code is great. One question.

    The team I'm building a workbook for gets data from several external sources, and many of the sheets appear similar and have the same name. This makes it hard to identify the sources of data just by looking at the sheets. However, each workbook will have a different file name.

    For example, if I pull in three files: Book1, Book2, Book3, and each of them has two sheets: SheetA, SheetB... After all is said and done, there isn't a clear way to distinguish which sheets came from where, since the sheet names will just be: SheetA, SheetB, SheetA (2), SheetB (2), SheetA (3), SheetB (3).

    Instead if they could be renamed to SheetABook1, SheetBBook1, SheetABook2, SheetBBook2, etc. they'd be more identifiable. Is there a way to have the VBA tack on the file name to the existing sheet names?
    • To post as a guest, your comment is unpublished.
      adamwgrise@gmail.com · 4 years ago
      Update: I have discovered that there is *just* enough variance in column headers such that I can identify which is which, and from there I can rename the sheets based on those properties. It appears that will work for now, but I'd be curious if it's still possible to do what I'd originally thought.
  • To post as a guest, your comment is unpublished.
    jay · 4 years ago
    Run-time error '1004':
    Copy method of worksheet class failed
  • To post as a guest, your comment is unpublished.
    kevin · 4 years ago
    I am using the code below to combined sheet 1 of multiple workbooks, but now I actually need to combine sheet 2 of multiple work books. Can any one please help me with what I need to change on the coding to combine sheet 2 instead of sheet 1.

    Sub MergeFilesWithoutSpaces()
    Dim path As String, ThisWB As String, lngFilecounter As Long
    Dim wbDest As Workbook, shtDest As Worksheet, ws As Worksheet
    Dim Filename As String, Wkb As Workbook
    Dim CopyRng As Range, Dest As Range
    Dim RowofCopySheet As Integer ThisWB = ActiveWorkbook.Name

    path = "c:\Test\"

    RowofCopySheet = 2

    Application.EnableEvents = False
    Application.ScreenUpdating = False

    Set shtDest = ActiveWorkbook.Sheets(1)
    Filename = Dir(path & "\*.xls", vbNormal)
    If Len(Filename) = 0 Then Exit Sub
    Do Until Filename = vbNullString
    If Not Filename = ThisWB Then Set Wkb = Workbooks.Open(Filename:=path & "\" & Filename)
    Set CopyRng = Wkb.Sheets(1).Range(Cells(RowofCopySheet, 1), Cells(Cells(Rows.Count, 1).End(xlUp).Row, Cells(1, Columns.Count).End(xlToLeft).Column))
    Set Dest = shtDest.Range("A" & shtDest.Cells(Rows.Count, 1).End(xlUp).Row + 1)
    CopyRng.Copy
    Dest.PasteSpecial xlPasteFormats
    Dest.PasteSpecial xlPasteValuesAndNumberFormats
    Application.CutCopyMode = False 'Clear Clipboard'
    Wkb.Close False

    End If

    Filename = Dir()

    Loop

    End Sub
    • To post as a guest, your comment is unpublished.
      dekeyser1976@gmail.com · 3 years ago
      Hi, I run into an syntaxis error while I execute this code (I also need just to combine sheet 1 from around 250 seperate .xls files into one file). I am not a VBA specialist.


      This below pops up in yellow.
      Sub MergeFilesWithoutSpaces()

      Another question: do I need to replace the "c:\test\"path by my path where these 250 .xls are stored?
      Any other modifications to this code?


      Much appreciated!
  • To post as a guest, your comment is unpublished.
    Hitesh · 4 years ago
    i want to combine data from multiple work books (excel file) whc includes 8 sheets
  • To post as a guest, your comment is unpublished.
    Lawrance · 4 years ago
    Error Line: Workbooks.Open Filename:=
  • To post as a guest, your comment is unpublished.
    ibra · 4 years ago
    how can I copy specific same cells for expamle (between A1-A15 for each excel sheet )from different files and paste all of them into a worksheet?
  • To post as a guest, your comment is unpublished.
    Shuk · 4 years ago
    Hi All
    I have successfully imported couple of excel spread sheets in one sheet by using below mentioned vb script:

    Sub GetSheets()
    Path = "Z:\.....\reports\"
    Filename = Dir(Path & "*.xls")
    Do While Filename ""
    Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
    For Each Sheet In ActiveWorkbook.Sheets
    Sheet.Copy After:=ThisWorkbook.Sheets(1)
    Next Sheet
    Workbooks(Filename).Close
    Filename = Dir()
    Loop

    However can anyone help me refining above script on how to import both the formats i.e. ".xls" and ".xlsx" of excel spread sheet by using single vb script.

    Any help would be much appreciated.
    • To post as a guest, your comment is unpublished.
      shuk · 4 years ago
      Got the solution for using both the formats i.e. ".xls" and ".xlsx" of excel spread sheet and code is given below:

      Sub GetSheet()
      Dim temp As String
      Path = "Z:\.....\reports\"
      Filename = Dir(Path & "*.xl??")
      Do While Filename ""
      Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
      temp = ActiveWorkbook.Name
      ActiveSheet.Name = ActiveSheet.Name
      ActiveWorkbook.Sheets(ActiveSheet.Name).Copy After:=ThisWorkbook.Sheets(1)
      Workbooks(Filename).Close
      Filename = Dir()
      Loop
      End Sub
  • To post as a guest, your comment is unpublished.
    Shuk · 4 years ago
    I have used below mentioned script and it was successful :-)

    Sub GetSheets()
    Dim temp As String
    Path = "Z:\.....\"
    Filename = Dir(Path & "*.xlsx")
    Do While Filename ""
    Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
    temp = ActiveWorkbook.Name
    ActiveSheet.Name = temp
    ActiveWorkbook.Sheets(temp).Copy After:=ThisWorkbook.Sheets(1)
    Workbooks(Filename).Close
    Filename = Dir()
    Loop
    End Sub

    However facing issue with two different format of excel spread sheets i.e. [b]"xls"[/b] and [b]"xlsx"[/b] which i would like to import. Any help would be greatly appreciated.
  • To post as a guest, your comment is unpublished.
    Johnny Bravo · 4 years ago
    When I click Finish for Combine Worksheets step 3 of 3,
    it asks me to save a file name,
    and then it just sits there.
  • To post as a guest, your comment is unpublished.
    Kevin Coutts · 4 years ago
    THE FOLLOWING CODE WORKED FOR ME IN EXCEL 2016. YOU NEED TO SPECIFY YOUR OWN DIRECTORY IN PLACE OF THE ONE I USED. IN MY CASE THE WERE REQUIRED IN THIS LINE (CONTRARY TO WHAT SOME OTHERS USED ABOVE): Do While Filename "".

    THE CODE THAT WORKED FOR ME FOLLOWS (I EMPLOYED THE STEPS OUTLINED IN THE ORIGINAL POST TO CREATE THIS CODE):


    Sub GetSheets()
    Path = "C:\Users\Kevin\Documents\Combine Excel Workbooks\Workbooks to Combine\"
    Filename = Dir(Path & "*.xlsx")
    Do While Filename ""
    Workbooks.Open Filename:=Path & Filename, ReadOnly:=False
    For Each Sheet In ActiveWorkbook.Sheets
    Sheet.Copy After:=ThisWorkbook.Sheets(1)
    Next Sheet
    Workbooks(Filename).Close
    Filename = Dir()
    Loop
    End Sub
    • To post as a guest, your comment is unpublished.
      Lawrance · 4 years ago
      Hi,


      When execute the above script Workbooks.Open Filename:= shows error expected statment. Could you please helpw me to resolve the issue
    • To post as a guest, your comment is unpublished.
      Lawrance · 4 years ago
      Hi All,


      When I execute the above script it shows Line 6 Char 27 Expected Statement. Could you please help me to resolve the issue.
  • To post as a guest, your comment is unpublished.
    Ma Hi · 4 years ago
    Thanks to every one,I have tried this program and it was helpful, I had 30 excel files and I wanted to merge them in "bahmann.xlsx".
    Sub GetSheets()
    Path = "C:\Users\16262\Desktop\bahman\"--- you have to put "\" at the end of your path
    Filename = Dir(Path & "*.xlsx")
    Do While Filename ""
    Workbooks.Open Filename:=Path & Filename, ReadOnly:=False
    For Each Sheet In ActiveWorkbook.Sheets
    Sheet.Copy After:=Workbooks("bahmann.xlsx").Sheets(1)
    Next Sheet
    Workbooks(Filename).Close
    Filename = Dir()
    Loop
    End Sub
  • To post as a guest, your comment is unpublished.
    E nic · 4 years ago
    Several excel files to merge using access?
    There are several files on the network.
  • To post as a guest, your comment is unpublished.
    Jan Drozd · 4 years ago
    Recently we we're solving this task for customer with more than 2000 different information types, hundreds of source excel files. They wanted to merge them into one big sheet to wok with.

    As a part of this work, we've developer Excel Stats Merger app: https://www.jandrozd.eu/products/excel-stats-merger/ - it does not require MS Office to do the job. You simply define merging rules and then process your files.
  • To post as a guest, your comment is unpublished.
    Mohideen · 4 years ago
    HI , I have multiple Excel File (single sheet) different folder with password protection. i want end of the day combine all data to one Master file. Every time I have to Enter password and open the file and copy paste to master file.. Kindly help me with VBA code for this please.
  • To post as a guest, your comment is unpublished.
    kannan · 5 years ago
    THANKS FOR THIS VALUABLE FORMULA....
    • To post as a guest, your comment is unpublished.
      Mohideen · 4 years ago
      HI , I have multiple Excel File (single sheet) different folder with password protection. i want end of the day combine all data to one Master file. Every time I have to Enter password and open the file and copy paste to master file.. Kindly help me with VBA code for this please.[quote name="kannan"]THANKS FOR THIS VALUABLE FORMULA....[/quote]
  • To post as a guest, your comment is unpublished.
    pat · 5 years ago
    I followed the instructions but when I Run a screen opens that lists Macros. I select GetSheets and Run but nothing happens.

    Sub GetSheets()
    Path = "G:\COM\Diabetes Center\Pat\Time Sheets\My time Sheet 2013"
    Filename = Dir(Path & "*.xlsx")
    Do While Filename ""
    Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
    For Each Sheet In ActiveWorkbook.Sheets
    Sheet.Copy After:=ThisWorkbook.Sheets(1)
    Next Sheet
    Workbooks(Filename).Close
    Filename = Dir()
    Loop
    End Sub
  • To post as a guest, your comment is unpublished.
    BWANG · 5 years ago
    Thanks. With some changes, the following works for me:

    Sub GetSheets() 'make sure the module is created in the current Excel spreadsheet "Weather data 201611.xlsx", not the "Personal.xlsb"
    Path = "C:\Weather Data\201611\" 'remember to change the file location here
    Filename = Dir(Path & "*.csv") ' .csv is the type of file while we wanted to open, change to xls or xlsx if required
    Do While Filename ""
    Workbooks.Open Filename:=Path & Filename, ReadOnly:=False 'Depending on the files which we want to open, if it is a read only file then change to ReadOnly:=True
    For Each Sheet In ActiveWorkbook.Sheets
    Sheet.Copy After:=Workbooks("Weather data 201611.xlsx").Sheets(1) 'Remember to change the file name to the file name while is new open for this module. Make sure the type match as well
    Next Sheet
    Workbooks(Filename).Close
    Filename = Dir()
    Loop
    End Sub
  • To post as a guest, your comment is unpublished.
    Rakesh G.B.Groups · 5 years ago
    i want to mix or update a excel file by a old file data and new file data
    please suggest me command

    Thank you
  • To post as a guest, your comment is unpublished.
    wackiemark · 5 years ago
    hello can anyone please help me with this problems in different codes.

    1.) copy all sheets in selected workbooks in a folder and paste it to current workbook. and if the worksheets have same sheetname, it will add a number e.g (1) on the side of the sheetname.

    2.) copy specific worksheet in selected workbooks and paste to current workbook, and if the worksheets have same sheetname, it will add a number e.g (1) on the side of the sheetname.

    thank you in advance
  • To post as a guest, your comment is unpublished.
    Ashwath · 5 years ago
    Hello, I tried this code for combining the files and it worked well. However I have a situation where in I have to combine the data from different sheets of multiple files in to one master file with multiple sheets.

    For ex: I have 10 different file and each file has data in Sheet 1 and Sheet 2. I want to create a consolidate data in to one master and all data from sheet 1 of multiple files should be consolidated in one sheet 1 of master and sheet 2 in sheet of master. Can this be done?