|
- Sub test3()
- ' Dim cnn As New ADODB.Connection
- ' Dim rs As New ADODB.Recordset
- Dim sql As String
- Dim mybook As String
- Dim cnn As Object
- Dim rs As Object
- Set cnn = CreateObject("adodb.connection")
- Set rs = CreateObject("adodb.recordset")
- mybook = ThisWorkbook.FullName
- With cnn
- If Application.Version = "11.0" Then
- .Provider = "microsoft.jet.oledb.4.0"
- .ConnectionString = "extended properties=""excel 8.0;HDR=YES;IMEX=1"";data source=" & mybook
- Else
- .Provider = "microsoft.ACE.oledb.12.0"
- .ConnectionString = "extended properties=""excel 12.0;HDR=YES;IMEX=1"";data source=" & mybook
- End If
- .Open
- End With
- sql = "select a.* from [上学期名单$a2:f] a where not isnull(学籍辅号) and a.学籍辅号 not in (select 学籍辅号 from [下学期名单$a2:a] where not isnull(学籍辅号))"
- rs.Open sql, cnn, adOpenKeyset, adLockOptimistic
- With Worksheets("减少名单")
- .Cells.Delete
- For j = 0 To rs.Fields.Count - 1
- .Cells(1, j + 1) = rs.Fields(j).Name
- Next
- .Range("a2").CopyFromRecordset rs
- End With
- rs.Close
- sql = "select a.* from [下学期名单$a2:f] a where not isnull(学籍辅号) and a.学籍辅号 not in (select 学籍辅号 from [上学期名单$a2:a] where not isnull(学籍辅号))"
- rs.Open sql, cnn, adOpenKeyset, adLockOptimistic
- With Worksheets("增加名单")
- .Cells.Delete
- For j = 0 To rs.Fields.Count - 1
- .Cells(1, j + 1) = rs.Fields(j).Name
- Next
- .Range("a2").CopyFromRecordset rs
- End With
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|