![]() |
#2
ictest2019-01-09 20:53
|

If Dir(Dir1.Path & "\合并导出", vbDirectory) = "" Then MkDir Dir1.Path & "\合并导出" '如果不存在文件夹则创建之
If Dir(Dir1.Path & "\合并导出\" & Trim(Label38.Caption) & "_MAP.xlsx") = "" Then
Set XlApp = CreateObject("Excel.Application")
Set xlBook = XlApp.Workbooks.Add
XlApp.Visible = False
Set xlsheet = xlBook.Worksheets(3)
XlApp.ScreenUpdating = False '屏幕更新关
xlBook.SaveAs (Dir1.Path & "\合并导出\" & Trim(Label38.Caption) & "_MAP.xlsx")
xlBook.Close
Set xlsheet = Nothing
Set xlBook = Nothing
XlApp.Quit
Set XlApp = Nothing '注意:xlApp要先Quit,后Nothing
End If
Set XlApp = CreateObject("Excel.Application")
Set xlBook = XlApp.Workbooks.Add
XlApp.DisplayAlerts = False '不显示对话框
Set newBook2 = XlApp.Workbooks.Open(Dir1.Path & "\合并导出\" & Trim(Label38.Caption) & "_MAP.xlsx")
Set newBook4 = XlApp.Workbooks.Open(Dir1.Path & "\SUMMARY.xlsx")
newBook2.Worksheets("Sheet3").Delete
newBook2.Worksheets("Sheet2").Delete
newBook4.Sheets("sheet1").Name = "统计信息"
newBook4.Sheets("统计信息").Copy after:=newBook2.Sheets(newBook2.Sheets.Count)
For i = 0 To File2.ListCount - 1
Set newBook1 = XlApp.Workbooks.Open(Dir1.Path & "\封装图导出\" & File2.List(i))
newBook1.Sheets(1).Copy after:=newBook2.Sheets(newBook2.Sheets.Count)
newApp.Visible = False
Next i
newBook2.Worksheets("Sheet1").Delete
newBook2.SaveAs (Dir1.Path & "\合并导出\" & Trim(Label38.Caption) & "_MAP.xlsx")
xlBook.SaveAs (Dir1.Path & "\合并导出\" & Trim(Label38.Caption) & "_MAP.xlsx")
'在退出窗体前,释放excel相应变量
newApp.Visible = False
XlApp.DisplayAlerts = False '不显示对话框
Set newBook1 = Nothing
Set newBook2 = Nothing
Set newBook3 = Nothing
Set newBook4 = Nothing
Set newApp = Nothing
xlBook.Close
Set xlsheet = Nothing
Set xlBook = Nothing
XlApp.Quit
Set XlApp = Nothing
If Dir(Dir1.Path & "\合并导出\" & Trim(Label38.Caption) & "_MAP.xlsx") = "" Then
Set XlApp = CreateObject("Excel.Application")
Set xlBook = XlApp.Workbooks.Add
XlApp.Visible = False
Set xlsheet = xlBook.Worksheets(3)
XlApp.ScreenUpdating = False '屏幕更新关
xlBook.SaveAs (Dir1.Path & "\合并导出\" & Trim(Label38.Caption) & "_MAP.xlsx")
xlBook.Close
Set xlsheet = Nothing
Set xlBook = Nothing
XlApp.Quit
Set XlApp = Nothing '注意:xlApp要先Quit,后Nothing
End If
Set XlApp = CreateObject("Excel.Application")
Set xlBook = XlApp.Workbooks.Add
XlApp.DisplayAlerts = False '不显示对话框
Set newBook2 = XlApp.Workbooks.Open(Dir1.Path & "\合并导出\" & Trim(Label38.Caption) & "_MAP.xlsx")
Set newBook4 = XlApp.Workbooks.Open(Dir1.Path & "\SUMMARY.xlsx")
newBook2.Worksheets("Sheet3").Delete
newBook2.Worksheets("Sheet2").Delete
newBook4.Sheets("sheet1").Name = "统计信息"
newBook4.Sheets("统计信息").Copy after:=newBook2.Sheets(newBook2.Sheets.Count)
For i = 0 To File2.ListCount - 1
Set newBook1 = XlApp.Workbooks.Open(Dir1.Path & "\封装图导出\" & File2.List(i))
newBook1.Sheets(1).Copy after:=newBook2.Sheets(newBook2.Sheets.Count)
newApp.Visible = False
Next i
newBook2.Worksheets("Sheet1").Delete
newBook2.SaveAs (Dir1.Path & "\合并导出\" & Trim(Label38.Caption) & "_MAP.xlsx")
xlBook.SaveAs (Dir1.Path & "\合并导出\" & Trim(Label38.Caption) & "_MAP.xlsx")
'在退出窗体前,释放excel相应变量
newApp.Visible = False
XlApp.DisplayAlerts = False '不显示对话框
Set newBook1 = Nothing
Set newBook2 = Nothing
Set newBook3 = Nothing
Set newBook4 = Nothing
Set newApp = Nothing
xlBook.Close
Set xlsheet = Nothing
Set xlBook = Nothing
XlApp.Quit
Set XlApp = Nothing