在“工程”的“引用”中選擇“microsoft excel 11.0”,"microsoft excel 11.0"看版本而定
Dim xlApp As New Excel.Application
Dim xlBook As New Excel.Workbook
Dim xlSheet As New Excel.Worksheet
Private Sub Command1_Click()
On Error Resume Next
'背景程序運作excel程式,并得到該工作簿
Set xlBook = xlApp.Workbooks.Open("f:/1.xls")
xlApp.Visible = False
'獲得該工作簿的“sheet1”表
Set xlSheet = xlBook.Sheets("sheet1")
xlSheet.Select
'抽取b2格子的資料并指派給text1.text
text1.Text = xlSheet.Range("b2")
'釋放資源,順序到過來的,表》》簿》》應用程式
Set xlSheet = Nothing
Set xlBook = Nothing
xlApp.Quit
Set xlApp = Nothing
End Sub