Excel精英培训网

 找回密码
 注册

SQL动态路径

热度 4已有 1628 次阅读2011-1-25 20:13 |

Public oCNN As New ADODB.Connection
Public oRST As New ADODB.Recordset
Public oRSTemp As ADODB.Recordset
Public iLastRow As Long, iLastCol As Long
'ThisWorkBook模块
Private Sub Workbook_Open()
    oCNN.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & ThisWorkbook.Path & "\jihua.mdb;"
    Application.EnableEvents = False
    oRST.Open "select * from 技术开发部", oCNN, adOpenKeyset, adLockPessimistic
    Sheet1.[A2].CopyFromRecordset oRST
    iLastRow = oRST.RecordCount + 1
    iLastCol = oRST.Fields.Count
    Application.EnableEvents = True
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    oCNN.Close
End Sub
'Sheet1模块
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Rows.Count = 1 And Target.Columns.Count = 1 And Target.Row < iLastRow _
       And Target.Row > 1 And Target.Column < iLastCol Then
        With oRST
            .Move Target.Row - 2, adBookmarkFirst
            .Fields(Target.Column) = CStr(Target.Value)
            .Update
        End With
    End If
End Sub
'Sheet2模块
Private Sub Worksheet_Activate()
    Sheet2.[DATASOR2].ClearContents
    Set oRSTemp = oRST.Clone()
    oRSTemp.Requery
    Sheet2.[A2].CopyFromRecordset oRSTemp
    oRSTemp.Close
End Sub

刚表态过的朋友 (0 人)

全部作者的其他最新日志

发表评论 评论 (4 个评论)

回复 nothingwmm 2011-1-25 23:35
现在还看不懂,收藏先
回复 ls 2011-3-12 21:04
收藏先
回复 海滨音诗 2011-6-28 21:45
我也是看不懂,不过现在在学SQL,先收藏。
回复 小安安 2011-7-21 10:06
   学习了 好东西
不过还没达到这个境界

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-24 02:33 , Processed in 0.385234 second(s), 6 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

返回顶部