Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-模块/函数/VBA

EXCEL(VBA)~SQL 经典写法范本汇集(四)

时 间:2012-04-10 09:14:50
作 者:欢乐小爪   ID:20149  城市:杭州
摘 要:EXCEL(VBA)~SQL 经典写法范本汇集(四)
正 文:

Sub WAIKUAN()
Dim sql As String
Dim adoConn As New ADODB.Connection
Dim CSMaxrow&, ChuangXing$, GongZB$
ChuangXing = Sheets("参数").Range("E1")
GongZB = Sheets("参数").Range("A1")
' On Error Resume Next
CSMaxrow = Sheets("参数").Range("B65536").End(xlUp).Row
Set adoConn = New ADODB.Connection
Set adoConn = CreateObject("ADODB.Connection")
' Conn.Open "dsn=excel files;dbq=" & ThisWorkbook.Path & "\001.xls"
' adoConn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data Source = " & ThisWorkbook.Path & "\" & ChuangXing & "\" & GongZB & ".xls"
adoConn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data Source = " & ActiveWorkbook.FullName
sql = "select 构件名称,构件代号,横长度,横数量,竖长度,竖数量,比重,相应工艺 from [参数$B2:K" & CSMaxrow & "] where (大样代码='" & DYDH & "') and (内外框='WKXC')"

' -------------------------------------------
'下面2句是从C盘读取 不用调用参数就是加载宏内
' adoConn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data Source = " & ThisWorkbook.Path & "\" & ChuangXing & "\" & GongZB & ".xls"
' sql = "select 构件名称,构件代号,横长度,横数量,竖长度,竖数量,比重,相应工艺 from [工艺表$B2:K" & CSMaxrow & "] where (大样代码='" & DYDH & "') and (内外框='WKXC')"

' -------------------------------------------


         Workbooks("111.xls").Sheets("下料").Range("J" & JJ).CopyFromRecordset adoConn.Execute(sql)
adoConn.Close: Set adoConn = Nothing
End Sub

 

相关索引:上一节  下一节



Access软件网QQ交流群 (群号:54525238)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助