Clear all * Create a test cursor Create cursor testcursor (Rcno i,cType c(10), nType i, dType d) Rand(-1) For ix = 1 to 200000 && Create 200000 recs cursor Insert into testcursor values ; (recco()+1,sys(2015), int(rand()*1000), date()-int(rand()*100)) Endfor #Define lnPerSheet 30000 Set sysformats on Set safety off lnTotal = reccount() Wait window nowait "Pls wait sending data to Excel..." Start = seconds() oExcel = createobject("Excel.application") With oExcel .workbooks.add && Add a new workbook lnMaxRows = .ActiveWorkBook.ActiveSheet.Rows.Count && Get max row count lnNeededSheets = ceiling( lnTotal / (lnMaxRows - 1) ) && 1 row header ? "Total Pages : "+padr(lnNeededSheets,3," ") With .ActiveWorkBook lnCurrentSheetCount = .sheets.count .sheets.add(,.sheets(lnCurrentSheetCount),; lnNeededSheets - lnCurrentSheetCount) && Add new sheets after old ones For ix = 1 to .sheets.count With .sheets.item(ix) .name = "Page "+padl(ix,3,"0") .activate =InsertGroup(ix, lnMaxRows-1) Endwith Endfor .sheets.item(1).activate Endwith .visible = .t. Endwith ? "Total Elapsed : ",seconds() - start Function InsertGroup Lparameters tnSheetNumber, tnMaxRows Local jx, lnPasteStart, lnPassCount, lnPasteRecco * VFP copies 16384 rows at max - 1 header row lnPasteStart = ( tnSheetNumber - 1 ) * tnMaxRows + 1 lnPasteEnd = min(reccount(), tnMaxRows * tnSheetNumber) lnPassCount = ceiling( (lnPasteEnd-lnPasteStart+1) / (16384 - 1)) For jx = 1 to lnPassCount lnPasteStart = (tnSheetNumber - 1)*tnMaxRows + (jx-1) * 16383 + 1 Copy to tempxl type xls for between(recno(),lnPasteStart,lnPasteEnd) With oExcel .workbooks.Open(sys(5)+curdir()+"TEMPXL.XLS") If jx > 1 .ActiveWorkBook.ActiveSheet.Rows(1).delete && Delete header row Endif .ActiveWorkBook.ActiveSheet.Cells(1,1).CurrentRegion.Copy .workbooks(1).sheets.Item(tnSheetNumber).activate lcRangeToPaste = "A"+ltrim(str(iif(jx=1, 1, 2)+(jx-1)*16383)) .workbooks(1).ActiveSheet.Range(lcRangeToPaste).PasteSpecial() _Cliptext = "" && Empty clipboard .workbooks(2).close(.f.) && Close - no save Endwith Erase "TEMPXL.XLS" Endfor ? "Page no : "+; padl(tnSheetNumber,3," ")+; "/"+; padr(lnNeededSheets,3," ")+ ; " Elapsed : ",seconds() - startCetin