Egenskaber". Klik på "Referencer" og derefter vælge " Tilføj". Vælg " COM" og klik på " Microsoft Excel 12,0 Object Library ". Klik på "OK". Dobbeltklik på " Button " på " Funktioner" ruden for at tilføje en ny knap styring til " Form1 ". Dobbeltklik på " Button1 " for at åbne " Form1.vb "-modulet .
3 Tryk på " Ctrl + A " og tryk " Delete " for at fjerne al kode . Kopier og indsæt følgende kode til din " Form1.vb "-modulet .
4
Import Microsoft.Office.Interop
Public Class Form1
Private Sub Button1_Click ( ByVal afsender Som System.Object , ByVal e Som System.EventArgs ) Handles Button1.Click
Dim ExcelApp Som New Excel.Application
ExcelApp.Visible = Sand
Dim ExcelWbks som Excel.Workbooks = ExcelApp.Workbooks
Dim ExcelWbk som Excel.Workbook = ExcelWbks.Add
Dim ExcelShts som Excel.Sheets = ExcelWbk.Worksheets
Dim ExcelSht da Excel . . arbejdsark = ExcelShts ( " Ark1 " )
ExcelSht.Range ( "A1" ) Value = "Dette er en Microsoft Excel Office 2007 Arbejdsark "
ExcelSht.SaveAs ( "C: \\ my2007ExcelWorkbook.xlsx " )
End Sub
End Class
5
Tryk på" F5 "for at køre dit program og klik på" Button1 "for at oprette en Microsoft Office Excel 2007-projektmappe .