文件名称:宏EXCEL代码
文件大小:514B
文件格式:TXT
更新时间:2016-08-27 11:07:08
宏EXCEL
Sub Macro1() Dim cnn As New ADODB.Connection Dim mydata As String, myTable As String, SQL As String mydata = "TEST" myTable = "Table1" With cnn.ConnectionString = "Provider=SQLOLEDB.1;" _& "User ID=sa;" & "Data Source=THTFCOMPUTER;" _& "Initial Catalog=" & mydata.Open End With SQL = "select 数量 from Table1 a right join [Excel 8.0;Database=" & ThisWorkbook.FullName & "].[" & ActiveSheet.Name & "] b on a.型号=b.型号" Range("b2").CopyFromRecordset cnn.Execute(SQL) cnn.Close Set cnn = Nothing End Sub