VB output data to Excel

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.