多个excel文档合并到一个excel文档里
2015-07-30 15:51
351 查看
1、将所有需要合并的excel复制到一个目录下;
2、在该目录下新建一个a.execl;
3、打开a.excel,邮件sheet1,选择“查看代码”;
4、将以下代码复制到当前页面,并运行:
sub 合并当前目录下所有工作簿的全部工作表()
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 with
end if
myname = dir
loop
range("a1").select
application.screenupdating = true
msgbox "共合并了" & num & "个工作薄下的全部工作表。如下:" & chr(13) & wbn, vbinformation, "提示"
end sub
2、在该目录下新建一个a.execl;
3、打开a.excel,邮件sheet1,选择“查看代码”;
4、将以下代码复制到当前页面,并运行:
sub 合并当前目录下所有工作簿的全部工作表()
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 with
end if
myname = dir
loop
range("a1").select
application.screenupdating = true
msgbox "共合并了" & num & "个工作薄下的全部工作表。如下:" & chr(13) & wbn, vbinformation, "提示"
end sub
相关文章推荐
- C++学习笔记(四)
- Servlet实现图片验证码
- [Linux] - CentOS 安装nginx
- 如何过上简单的生活
- with: __enter__ and __exit__
- C#生成Code39条形码【非条形码字体】
- SSH配置拦截器
- neutron router-update如何增加路由
- 黑马程序员--C语言-指针函数及应用
- mongodb的用户认证
- java string 中文转换UTF-8
- 面向对象链接整理
- android:gravity="right" 没有居右侧
- Android 客户端登陆超时退出处理方案
- Eclipse 编译错误 Access restriction:The type *** is not accessible due to restriction on... 解决方案
- mysql处理上百万条的数据库如何优化语句来提高处理查询效率
- linux下vsftp软件正常启动了,也能正常连接,但是就是没办法正常浏览文件夹
- C#生成Code39条形码【非条形码字体】
- USB的枚举过程--自己写的(转载)
- Eclipse/MyEclipse自动补全的设置(自动提示)