本文介绍了如何导出Excel工作表到新的工作簿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆包含多个工作表的Excel工作簿中。我想遍历每个工作簿和每个工作表导出到它自己的新工作簿。我想每一个新的工作簿中的一张工作表。

下面是我有这么远:

 子ExportWorksheet(BYVAL工作表Excel.Worksheet,BYVAL文件路径作为字符串)
      昏暗xlApp作为Excel.Application =新Excel.ApplicationClass
      昏暗xlWorkBook作为Excel.Workbook = xlApp.Workbooks.Add
      worksheet.Select()
      worksheet.Copy()
      xlWorkBook.Worksheets.Add()
      worksheet.Paste(目的地:= xlWorkBook)

      xlWorkBook.SaveAs(文件名:=文件路径)

      xlWorkBook.Close(假)
      xlApp.Quit()
   结束小组
 

解决方案

卫生署!

worksheet.SaveAs(文件名:=文件路径)

I have a bunch of Excel workbooks that contain multiple worksheets. I want to loop through each workbook and export each worksheet into it's own new workbook. I want one worksheet in each new workbook.

Here's what I've got so far:

   Sub ExportWorksheet(ByVal worksheet As Excel.Worksheet, ByVal filePath As String)
      Dim xlApp As Excel.Application = New Excel.ApplicationClass
      Dim xlWorkBook As Excel.Workbook = xlApp.Workbooks.Add
      worksheet.Select()
      worksheet.Copy()
      xlWorkBook.Worksheets.Add()
      worksheet.Paste(Destination:=xlWorkBook)

      xlWorkBook.SaveAs(Filename:=filePath)

      xlWorkBook.Close(False)
      xlApp.Quit()
   End Sub
解决方案

Doh!

worksheet.SaveAs(Filename:=filePath)

这篇关于如何导出Excel工作表到新的工作簿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 21:33