How to export Excel worksheets into new workbooks

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
Does this work for one worksheet?

以上就是How to export Excel worksheets into new workbooks的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » excel

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准