西安飞宜宾:Excel VBA ADO 问题 - VB / VBA
来源:百度文库 编辑:九乡新闻网 时间:2024/05/02 13:48:15
Private Sub Button3_Click()
Dim conn As New ADODB.Connection
Dim res As New ADODB.Recordset
Dim str As String
conn.ConnectionString = "Server=10.102.120.197; Driver=SQL Server; " & _
"Database=DBCentre;"
On Error Resume Next
conn.Open
On Error GoTo 0
'If conn.State = adStateOpen Then
' MsgBox "到DBCentre的连接成功!", vbInformation, "连接数据库"
'Else
' MsgBox "连接失败!", vbInformation, "连接数据库"
'End If
Dim i, j As Integer
j = 1
str = "select * from 1"
res.Open str, conn
Worksheets("sheet2").unproted
Worksheets("sheet2").Cells.ClearContents
While Not res.EOF
For i = 1 To res.Fields.Count - 1
Sheet2.Cells(j, i).Rows.Value = res.Fields(i).Value
Next i
j = j + 1
res.MoveNext
Wend
MsgBox "读取完毕", vbInformation, "文件读取情况"
res.Clone
conn.Close
Worksheet("sheet1").Activate
End Sub
这段代码是我最近才写的.但是一直提示"子过程或函数未定义"请问代码有什么问题吗?
Dim conn As New ADODB.Connection
Dim res As New ADODB.Recordset
Dim str As String
conn.ConnectionString = "Server=10.102.120.197; Driver=SQL Server; " & _
"Database=DBCentre;"
On Error Resume Next
conn.Open
On Error GoTo 0
'If conn.State = adStateOpen Then
' MsgBox "到DBCentre的连接成功!", vbInformation, "连接数据库"
'Else
' MsgBox "连接失败!", vbInformation, "连接数据库"
'End If
Dim i, j As Integer
j = 1
str = "select * from 1"
res.Open str, conn
Worksheets("sheet2").unproted
Worksheets("sheet2").Cells.ClearContents
While Not res.EOF
For i = 1 To res.Fields.Count - 1
Sheet2.Cells(j, i).Rows.Value = res.Fields(i).Value
Next i
j = j + 1
res.MoveNext
Wend
MsgBox "读取完毕", vbInformation, "文件读取情况"
res.Clone
conn.Close
Worksheet("sheet1").Activate
End Sub
这段代码是我最近才写的.但是一直提示"子过程或函数未定义"请问代码有什么问题吗?
Excel VBA ADO 问题 - VB / VBA
Excel VBA
EXCEL VBA 排序
EXCEL VBA 基础
Excel VBA语句集
vba]-Excel VBA命令(转)
EXCEL 2003 VBA与宏
Excel VBA的常用命令举例
Excel VBA 300语句集
Excel VBA语句集a
Excel VBA教程:Item属性
Excel?VBA的封装,加密
Excel VBA典型实例大全
Excel VBA 自动填充公式
vb ado datagrid 数据导出到excel
Excel VBA金融必看国外书籍
Excel VBA(宏)精简(四)---
利用VBA宏代码把Excel单元
使用 Excel 2003 工作表的 VBA
Excel VBA编程的常用代码a
学习 Excel VBA 中的类模块
Excel VBA编程的常用代码22
Excel VBA编程的常用代码1
用VBA(编程)保护Excel文档