Skip i'r prif gynnwys

Sut i gyfuno nifer o lyfrau gwaith yn un prif lyfr gwaith yn Excel?

Ydych chi erioed wedi bod yn sownd pan mae'n rhaid i chi gyfuno nifer o lyfrau gwaith yn brif lyfr gwaith yn Excel? Y peth mwyaf ofnadwy yw bod y llyfrau gwaith y mae angen i chi eu cyfuno yn cynnwys nifer o daflenni gwaith. A sut i gyfuno dim ond taflenni gwaith penodedig llyfrau gwaith lluosog mewn un llyfr gwaith? Mae'r tiwtorial hwn yn dangos sawl dull defnyddiol i'ch helpu chi i ddatrys y broblem fesul cam.


Cyfuno nifer o lyfrau gwaith I mewn i un llyfr gwaith â swyddogaeth Symud neu Gopïo

Os oes dim ond cwpl o lyfrau gwaith y mae angen eu cyfuno, gallwch ddefnyddio'r gorchymyn Symud neu Gopïo i symud neu gopïo taflenni gwaith o'r llyfr gwaith gwreiddiol i'r prif lyfr gwaith.

1. Agorwch y llyfrau gwaith y byddwch chi'n eu huno yn brif lyfr gwaith.

2. Dewiswch y taflenni gwaith yn y llyfr gwaith gwreiddiol y byddwch chi'n eu symud neu'n eu copïo i'r prif lyfr gwaith.

Nodiadau:

1). Gallwch ddewis nifer o daflenni gwaith nad ydynt yn gyfagos â dal y Ctrl allwedd a chlicio ar y tabiau dalen fesul un.

2). I ddewis nifer o daflenni gwaith cyfagos, cliciwch ar y tab dalen gyntaf, daliwch y Symud allwedd, ac yna cliciwch y tab dalen olaf i'w dewis i gyd.

3). Gallwch glicio ar dde ar unrhyw dab dalen, cliciwch ar Dewiswch Pob Dalen o'r ddewislen cyd-destun i ddewis yr holl daflenni gwaith yn y llyfr gwaith ar yr un pryd.

3. Ar ôl dewis y taflenni gwaith sydd eu hangen, cliciwch ar y dde ar y tab dalen, ac yna cliciwch Symud neu Gopïo o'r ddewislen cyd-destun. Gweler y screenshot:

4. Yna y Symud neu Gopïo deialog pops i fyny, yn y I archebu gwymplen, dewiswch y prif lyfr gwaith y byddwch chi'n ei symud neu'n copïo taflenni gwaith iddo. Dewiswch symud i ddiweddu yn y Cyn y ddalen blwch, gwiriwch y Creu copi blwch, ac yn olaf cliciwch y OK botwm.

Yna gallwch weld taflenni gwaith mewn dau lyfr gwaith wedi'u cyfuno'n un. Ailadroddwch y camau uchod i symud taflenni gwaith o lyfrau gwaith eraill i'r prif lyfr gwaith.


Cyfuno nifer o lyfrau gwaith neu ddalenni penodol o lyfrau gwaith â phrif lyfr gwaith gyda VBA

Os oes angen uno nifer o lyfrau gwaith yn un, gallwch gymhwyso'r codau VBA canlynol i'w gyflawni'n gyflym. Gwnewch fel a ganlyn.

1. Rhowch yr holl lyfrau gwaith rydych chi am eu cyfuno mewn un o dan yr un cyfeiriadur.

2. Lansio ffeil Excel (y llyfr gwaith hwn fydd y prif lyfr gwaith).

3. Gwasgwch y Alt + F11 allweddi i agor y Microsoft Visual Basic ar gyfer cymwysiadau ffenestr. Yn y Microsoft Visual Basic ar gyfer cymwysiadau ffenestr, cliciwch Mewnosod > Modiwlau, yna copïwch isod god VBA i mewn i ffenestr y Modiwl.

Cod VBA 1: Uno nifer o lyfrau gwaith Excel yn un

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
	

Nodiadau:

1. Bydd y cod VBA uchod yn cadw enwau dalennau'r llyfrau gwaith gwreiddiol ar ôl uno.

2. Os ydych chi am wahaniaethu pa daflenni gwaith yn y prif lyfr gwaith a ddaeth o ble ar ôl uno, cymhwyswch y cod 2 VBA isod.

3. Os ydych chi am gyfuno taflenni gwaith penodol o'r llyfrau gwaith yn brif lyfr gwaith, gall y cod VBA 3 isod helpu.

Mewn codau VBA, “C: \ Defnyddwyr \ DT168 \ Pen-desg \ KTE \”Yw llwybr y ffolder. Yn y cod VBA 3, "Taflen1, Taflen3"yw taflenni gwaith penodedig y llyfrau gwaith y byddwch chi'n eu cyfuno i brif lyfr gwaith. Gallwch eu newid yn seiliedig ar eich anghenion.

Cod VBA 2: Uno Llyfrau Gwaith yn un (bydd pob taflen waith yn cael ei henwi â rhagddodiad enw ei ffeil wreiddiol):

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

Cod VBA 3: Uno taflenni gwaith penodedig o lyfrau gwaith yn brif lyfr gwaith:

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. Gwasgwch y F5 allwedd i redeg y cod. Yna mae'r holl daflenni gwaith neu daflenni gwaith penodol o'r llyfrau gwaith yn y ffolder benodol yn cael eu cyfuno â phrif lyfr gwaith ar unwaith.


Cyfuno sawl llyfr gwaith neu ddalen benodol o lyfrau gwaith yn hawdd i un llyfr gwaith

Yn ffodus, mae'r Cyfunwch llyfr gwaith cyfleustodau Kutools ar gyfer Excel yn ei gwneud hi'n llawer haws uno nifer o lyfrau gwaith yn un. Dewch i ni weld sut i gael y swyddogaeth hon i weithio wrth gyfuno nifer o lyfrau gwaith.

Cyn gwneud cais Kutools ar gyfer Excel, os gwelwch yn dda ei lawrlwytho a'i osod yn gyntaf.

1. Creu llyfr gwaith newydd a chlicio Kutools Byd Gwaith > Cyfunwch. Yna deialog pops i'ch atgoffa y dylid arbed yr holl lyfrau gwaith cyfun ac na ellir defnyddio'r nodwedd ar lyfrau gwaith gwarchodedig, cliciwch ar y OK botwm.

2. Yn y Cyfuno Taflenni Gwaith dewin, dewiswch Cyfuno nifer o daflenni gwaith o lyfrau gwaith yn un llyfr gwaith opsiwn, ac yna cliciwch ar y Digwyddiadau botwm. Gweler y screenshot:

3. Yn y Cyfuno Taflenni Gwaith - Cam 2 o 3 blwch deialog, cliciwch y Ychwanegu > Ffeil or Ffolder i ychwanegu'r ffeiliau Excel byddwch chi'n uno yn un. Ar ôl ychwanegu'r ffeiliau Excel, cliciwch y Gorffen botwm a dewis ffolder i achub y prif lyfr gwaith. Gweler y screenshot:

Nawr mae'r holl lyfrau gwaith wedi'u huno yn un.

O'i gymharu â'r ddau ddull uchod, Kutools ar gyfer Excel Mae ganddo'r manteision canlynol:

  • 1) Rhestrir yr holl lyfrau gwaith a thaflenni gwaith yn y blwch deialog;
  • 2) Ar gyfer y taflenni gwaith rydych chi am eu heithrio rhag uno, dim ond ei ddad-dicio;
  • 3) Mae taflenni gwaith gwag yn cael eu heithrio'n awtomatig;
  • 4) Ychwanegir enw'r ffeil wreiddiol fel rhagddodiad at enw'r ddalen ar ôl uno;
  • Am fwy o swyddogaethau'r nodwedd hon, ewch yma.

  Os ydych chi am gael treial am ddim (30 diwrnod) o'r cyfleustodau hwn, cliciwch i'w lawrlwytho, ac yna ewch i gymhwyso'r llawdriniaeth yn ôl y camau uchod.


Kutools ar gyfer Excel - Yn Eich Helpu Bob Amser i Orffen Gwaith Cyn Amser, Cael mwy o amser i fwynhau bywyd
Ydych chi'n aml yn cael eich hun yn chwarae dal i fyny â gwaith, diffyg amser i'w dreulio i chi'ch hun a'ch teulu?  Kutools ar gyfer Excel gall eich helpu i ddelio â 80% Posau Excel a gwella effeithlonrwydd gwaith 80%, rhoi mwy o amser i chi ofalu am deulu a mwynhau bywyd.
300 o offer datblygedig ar gyfer 1500 o senarios gwaith, gwnewch eich swydd gymaint yn haws nag erioed.
Nid oes angen fformiwlâu a chodau VBA ar gof mwyach, rhowch orffwys i'ch ymennydd o hyn ymlaen.
Gellir gwneud gweithrediadau cymhleth ac ailadroddus brosesu un-amser mewn eiliadau.
Gostyngwch filoedd o lawdriniaethau bysellfwrdd a llygoden bob dydd, ffarweliwch â chlefydau galwedigaethol nawr.
Dewch yn arbenigwr Excel mewn 3 munud, helpwch chi i gael eich cydnabod yn gyflym a dyrchafiad codi cyflog.
110,000 o bobl hynod effeithiol a 300+ o ddewisiadau cwmnïau byd-enwog.
Gwnewch eich $ 39.0 werth mwy na $ 4000.0 hyfforddiant eraill.
Nodwedd lawn am ddim treial 30-diwrnod. Gwarant Arian yn Ôl 60-Diwrnod heb reswm.

Comments (146)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I have one workbook with 100+ sheets, I want to move all 100+ sheets into another workbook in a single sheet.
This comment was minimized by the moderator on the site
I had to read throught the comments to find suggestions that worked for my application of the VBA CODE 2, but I managed to get it to work doing the following things:
1. make sure to change "C:\Users\DT168\Desktop\KTE\" to your own directory to wherever you have your files are located. don't forget the extra "\" at the end!2. my spreadsheets were extension ".xls", so I deleted the extra "x" in this line, like so: xStrFName = Dir(xStrPath & "*.xlsx")3. I placed all my spreadsheets in a single folder, and only those files were the contents of that folder, the target macro enabled spreadsheet where this vba was running from was saved outside of this folder (hopefully this makes sense).
one thing that I didn't want to mess with though is I only needed to merge the 1st tab of each spreadsheet, but I didn't want to mess with the code so if each workbook you want to merge into one has multiple tabs, this code will grab all of the tabs on each workbook and place them in your target spreadsheet, I had to manually delete all the tabs I didn't want.
if the author of this vba could reply to me, how do you change the code to just copy the 1st tab as opposed to all the tabs?
thank you!
This comment was minimized by the moderator on the site
hi I want a change. If the the sheet name is same then the data should be appended in the same name sheet rather than adding a sheet. for example if i have 10 files with jan, feb, mar same sheetnames. then result should be 1 file having jan, feb, mar only 3 sheets with the data of all 10 files. thanks
This comment was minimized by the moderator on the site
Good morning,

Basically I have to copy the values of another file example c: \ test.xlsx (sheet name "date"):

I have to copy the values from A2: T20


And I have to paste in another Extract.xlsx file on the “Extracts” folder on A2.


PLEASE NOTE: You must run vba when opening the file.
This comment was minimized by the moderator on the site
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?
This comment was minimized by the moderator on the site
Hello any one can help me, I want to combine sheet 2 only from 5 different sheet, can you script for me.
This comment was minimized by the moderator on the site
you can use Array function to copy the multiple sheets to combine in one file
Sheets(Array("Sheet1","Sheet2")).copy
This comment was minimized by the moderator on the site
hai sir i want know code for copying multiple sheets in one excel to multiple excels
This comment was minimized by the moderator on the site
Sheets(Array("Sheet1","Sheet2")).copy
This comment was minimized by the moderator on the site
hai sir i want know code for copying multiple sheets in one excel to multiple excels
This comment was minimized by the moderator on the site
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
This comment was minimized by the moderator on the site
What part of VBA code 3 specifies the name of the worksheet to be copied?
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations