回复 25 楼 tanxiaobin
朋友,这些语句放在EXCEL的VBA中代码应该如何修改呢?
我的VBA是这样的:
Sub GetData1()
Dim server As String
Dim strDatabase As String
Dim user As String
Dim pwd As String
Dim djhcx As String
server = Cells(3, 8).Value
strDatabase = Cells(4, 8).Value
user = Cells(5, 8).Value
pwd = Cells(6, 8).Value
djhcx = Cells(7, 8).Value
Dim conn0
Set conn0 = CreateObject("ADODB.Connection")
conn0.Open ("driver={SQL Server};server=" & server & ";uid=" & user & ";pwd=" & pwd & ";database=" & strDatabase & ";")
sql0 = "select 地籍号1 from MA33 where 地籍号1 like'" & djhcx & "%' ORDER BY 地籍号1"
sql00 = "select count(*) as 记录数 from MA33 where 地籍号1 like'" & djhcx & "%'"
Dim ds0
Set ds0 = CreateObject("ADODB.Recordset")
With ds0
.Open sql0, conn0
Range("a2:a65536").ClearContents
Range("a1").Offset(1, 0).CopyFromRecordset ds0
End With
Set ds0 = Nothing
Dim ds00
Set ds00 = CreateObject("ADODB.Recordset")
With ds00
.Open sql00, conn0
MsgBox "从EXCEL第二行格开始,根据数据查询条件" & djhcx & ",共从苍穹图形库" & strDatabase & "中读取" & ds00("记录数") & "条数据记录更新到EXCEL的A列(图形地籍号)之中!", 16, "A列(图形地籍号)数据更新"
End With
Set ds00 = Nothing
conn0.Close
Set conn0 = Nothing
MsgBox "此次数据更新完成!", 16, "温馨提示"
Exit Sub
End Sub
[
本帖最后由 liudetao 于 2014-11-7 17:09 编辑 ]