|
楼主 |
发表于 2015-8-17 15:27
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Private Sub CommandButton1_Click()
Dim cnn As Object, sql As String
Range(Cells(5, 2), Cells(11, 26)).Clear
Set cnn = CreateObject("adodb.connection")
On Error Resume Next
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" & ThisWorkbook.FullName '创建数据库连接
If Err <> 0 Then
MsgBox "打不开文件,它已经被别的用户以独占方式打开!"
Err = 0
Exit Sub
End If
sql = "select* from [数据表$B4:Y11]"
Cells(5, 2).CopyFromRecordset cnn.Execute(sql)
cnn.Close
Set cnn = Nothing
UserForm1.Hide
'Unload Me
End Sub
|
|