在工程中引用Microsoft Excel类型库: 从"工程"菜单中选择"引用"栏;选择Microsoft Excel 9.0 Object Library(EXCEL2000),然后选择"确定"。表示在工程中要引用EXCEL类型库。Dim xlApp As Excel.Application Dim xlBook As Excel.WorkBook Dim xlSheet As Excel.Worksheet Private Sub Command1_Click() '更新EXCEL If Dir("D:\temp\excel.bz") = "" Then '判断EXCEL是否打开 Set xlApp = CreateObject("Excel.Application") '创建EXCEL应用类 xlApp.Visible = True '设置EXCEL可见 Set xlBook = xlApp.Workbooks.Open("D:\temp\bb.xls") '打开EXCEL工作簿 Set xlsheet = xlBook.Worksheets(1) '打开EXCEL工作表 xlsheet.Activate '激活工作表 xlsheet.Cells(1, 1) = TextBox1.Text '给单元格1行驶列赋值 xlBook.Close (True) '关闭工作簿 xlApp.Quit '结束EXCEL对象 Set xlApp = Nothing '释放xlApp对象 Else MsgBox ("EXCEL已打开") End If End Sub
这个与textbox无excel根本无关,关键在于ado打开excel文件的方式,找看看。
从"工程"菜单中选择"引用"栏;选择Microsoft Excel 9.0 Object Library(EXCEL2000),然后选择"确定"。表示在工程中要引用EXCEL类型库。Dim xlApp As Excel.Application
Dim xlBook As Excel.WorkBook
Dim xlSheet As Excel.Worksheet
Private Sub Command1_Click() '更新EXCEL
If Dir("D:\temp\excel.bz") = "" Then '判断EXCEL是否打开
Set xlApp = CreateObject("Excel.Application") '创建EXCEL应用类
xlApp.Visible = True '设置EXCEL可见
Set xlBook = xlApp.Workbooks.Open("D:\temp\bb.xls") '打开EXCEL工作簿
Set xlsheet = xlBook.Worksheets(1) '打开EXCEL工作表
xlsheet.Activate '激活工作表
xlsheet.Cells(1, 1) = TextBox1.Text '给单元格1行驶列赋值
xlBook.Close (True) '关闭工作簿
xlApp.Quit '结束EXCEL对象
Set xlApp = Nothing '释放xlApp对象
Else
MsgBox ("EXCEL已打开")
End If
End Sub