在“工程”的“引用”中选择“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
|