I have one workbook with a giant worksheet, say 4000 lines. I want to copy those lines and paste it into another workbook so that it will be split up and have 4 separate sheets with 1000 lines each. I am using visual basic and this is what I have so far.
ReadOnly FileName As String = "C:\Programming\LoadingFiles\MyTest1.xlsx"
ReadOnly DestinationFileName As String = "C:\Programming\LoadingFiles\Cache\Result.xlsx"
Sub SplitIntoMultipleSheets()
Dim xlApp As New Application
Dim xlDestinationApp As New Application
Dim xlSourceWkbk As Workbook = xlApp.Workbooks.Open(FileName)
Dim xlDestinationWkbk As Workbook = xlDestinationApp.Workbooks.Open(DestinationFileName)
Try
Console.Write("Source sheet count: " + xlSourceWkbk.Sheets.Count.ToString() + " ")
Console.Write("~ Destination sheet count: " + xlDestinationWkbk.Sheets.Count.ToString())
xlDestinationWkbk.Worksheets.Add(After:=xlDestinationWkbk.Sheets(xlDestinationWkbk.Sheets.Count)
)
xlDestinationWkbk.Save()
xlDestinationWkbk.Close()
xlSourceWkbk.Close()
System.Diagnostics.Process.Start(DestinationFileName)
Catch ex As Exception
xlDestinationWkbk.Close()
xlSourceWkbk.Close()
End Try
End Sub