✔ 最佳答案
'專案>加入參考(請擇一)>Microsoft.Office.Interop(.NET)
' Microsoft Excel 11.0 Object Library(COM)
'\/若有加入參考\/
Imports Microsoft.Office.Interop
'/\若有加入參考/\
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'\/若有加入參考\/
Dim myXls As New Excel.Application
'或者是(如果沒有寫第一行的 Imports)
'Dim myXls As New Microsoft.Office.Interop.Excel.Application
Dim myBooks As New Excel.Application
Dim mySht As New Excel.Worksheet
'/\若有加入參考/\
'若無加入參考\/
'Dim myXls, myBooks, mySht As Object
'myXls = CreateObject("Excel.Application")
'/\若無加入參考/\
With myXls
.Workbooks.Add() '建立新檔
'.Workbooks.Open("C:\Books.xls")'開啟舊檔(含完整路徑)
.Visible = True '顯示 Excel
End With
myBooks = myXls.Workbooks.Application
mySht = myBooks.Sheets("Sheet1") '取得工作表名稱
With mySht
.Select() '選擇工作表
'MsgBox(.Application.ActiveCell.Row) '顯示目前選擇儲存格的 Row
'MsgBox(.Application.ActiveCell.Column) '顯示目前選擇儲存格的 Column
.Range("A1").Value = "資料" '在 A1 儲存格輸入 資料
'MsgBox(.Range("A1").Value) '顯示 A1 儲存格的資料
End With
End Sub
End Class