Private SubCommand1_Click ()DimI as Long DimJ as Long DimMyData (Ten,Ten) as Long Dimxlapp, WS, WBSetxlapp =CreateObject("Excel.Application") SetWB =XLAPP.WORKBOOKS.ADDSetWS = WB. Sheets (1) fori =0 to Ten forj =0 to TenWS. Cells (i+1, J +1). Value = MyData (i, J)'write to section i+1, column j+1 NextJNextI xlapp.visible=True Setxlapp = Nothing SetWS = Nothing SetWB = NothingEnd Sub
Above is only shown to view, if you want to file operations, you can also:
Private SubCommand1_Click ()DimI as LongDimJ as LongDimMyData (Ten,Ten) as LongDimxlappSetxlapp =CreateObject("Excel.Application")'Create an Excel objectXlApp.WorkBooks.Open ("D:\123.xls") Xlapp.worksheets ("Sheet1"). Activate fori =0 to Ten ifI>5 ThenXlapp.worksheets ("Sheet2"). Activate forj =0 TenXlapp.cells (i+1, J +1). Value = MyData (i, J)'write to section i+1, column j+1 NextJNextI'Save'XlApp.ActiveWorkbook.Save' Save'xlApp.ActiveWorkbook.SaveAs "D:\456.xls"'show up'xlapp.visible = True'Close'XlApp.WorkBooks.Close'xlApp.QuitSetxlapp = NothingEnd Sub
VB output data to Excel