请问,VB可以在一个程序中同时连接两个EXCEL吗?如果能应该怎样连接,谢谢
1个回答
展开全部
当然可以
Dim adoConnection1 As New ADODB.Connection
Dim adoRecordset1 As New ADODB.Recordset
Dim adoConnection2 As New ADODB.Connection
Dim adoRecordset2 As New ADODB.Recordset
'OLE DB + ODBC Driver 方式:
adoConnection1.Open "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=e:\temp\book1.xls"
adoConnection2.Open "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=e:\temp\book2.xls"
Dim adoConnection1 As New ADODB.Connection
Dim adoRecordset1 As New ADODB.Recordset
Dim adoConnection2 As New ADODB.Connection
Dim adoRecordset2 As New ADODB.Recordset
'OLE DB + ODBC Driver 方式:
adoConnection1.Open "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=e:\temp\book1.xls"
adoConnection2.Open "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=e:\temp\book2.xls"
更多追问追答
追问
我试了一下,说用户定义类型未定义Dim adoConnection1 As New ADODB.Connection
我已经添加了excel 的 引用,是不是还需要添加其他的引用,可否给一个完整的连接两个excel表格的程序,谢谢
追答
还要添加 Microsoft activeX data objects 2.8...这个引用。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询