|
楼主 |
发表于 2015-8-17 15:27
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
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
|
|