How to merge over 100 Excel files into one

Source: Internet
Author: User

From: http://zhidao.baidu.com/question/96195372.html

Create a worksheet, name it, and save it to the same file folder as the merged 100 files, press Alt + F11, double-click sheet1 (sheet1) in the project resource manager, and click Code Paste the following code. Run. Wait for a while and then OK.

Sub: merge all worksheets of all workbooks in the current directory ()
Dim mypath, myname, awbname
Dim WB as workbook, wBN as string
Dim G as long
Dim num as long
Dim box as string
Application. screenupdating = false
Mypath = activeworkbook. Path
Myname = Dir (mypath & "\" & "*. xls ")
Awbname = activeworkbook. Name
Num = 0
Do While myname <> ""
If myname <> awbname then
Set WB = workbooks. Open (mypath & "\" & myname)
Num = num + 1
With workbooks (1). activesheet
. Cells (. Range ("a65536"). End (xlup). Row + 2, 1) = left (myname, Len (myname)-4)
For G = 1 to sheets. Count
WB. Sheets (g). usedrange. Copy. cells (. Range ("a65536"). End (xlup). Row + 1, 1)
Next
WBN = wBN & CHR (13) & WB. Name
WB. Close false
End
End if
Myname = dir
Loop
Range ("A1"). Select
Application. screenupdating = true
Msgbox combines all worksheets in the "& num &" workbook. As follows: "& CHR (13) & wBN, vbinformation," prompt"
End sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.