| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1320 人关注过本帖
标题:亲,想制作一个一键生成程序,把EXCEL合并成一个表里?
只看楼主 加入收藏
inluck
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2019-12-17
收藏
 问题点数:0 回复次数:0 
亲,想制作一个一键生成程序,把EXCEL合并成一个表里?
Private Sub Command1_Click()
Dim MyPath, MyName, AWbName
Dim WbN As String
Dim G As Long
Dim Num As Long
Dim BOX As String


Dim EXAPP As Excel.Application
 Dim WB As Excel.Workbook
 Dim sht As Excel.Worksheet
 Set EXAPP = CreateObject("excel.application")
 Set WB = EXAPP.Workbooks.Open("d:\gz\汇总2019.xlsx")

'Set WB = Excel.Workbooks.Open(MyPath & "\" & MyName)
 Set sht = WB.Worksheets("总表")



Excel.Application.ScreenUpdating = False
MyPath = "D:\gz"
MyName = Dir(MyPath & "\" & "*.xls")
AWbName = "汇总2019"
Num = 0
Do While MyName <> ""
If MyName <> AWbName Then
'Set WB = Excel.Workbooks.Open(MyPath & "\" & MyName)
Num = Num + 1
With Workbooks(1).ActiveSheet.Cells(sht.Range("A65536").End(xlUp).Row + 2, 1) = Left(MyName, Len(MyName) - 4)
For G = 1 To Sheets.Count
WB.Sheets(G).UsedRange.Copy.Cells=(sht.Range("A65536").End(xlUp).Row + 1)1)


WbN = WbN & Chr(13) & WB.Name
WB.Close False
End With
End If
MyName = Dir
Loop


sht.Rows("1:1").Select
    sht.Range("A1").Activate
   

'Range("A1").Select
Application.ScreenUpdating = True
MsgBox "共合并了" & Num & "个工作薄下的全部工作表。如下:" & Chr(13) & WbN, vbInformation, "提示"



EXAPP.Workbooks.Close
EXAPP.Quit
Set EXAPP = Nothing


End Sub
图中红色部门,在运行时,出现红色。请问如何表达这个
搜索更多相关主题的帖子: Set Num End Dim EXCEL 
2019-12-17 15:59
快速回复:亲,想制作一个一键生成程序,把EXCEL合并成一个表里?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015775 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved