|
经典图书 - '连接Excel
- Sub updateaddRecords2003()
- '引用Microsoft ActiveX Data Objects 6.1 Library
- Dim myPath As String
- Dim myTable As String
- Dim strTemp As String
- Dim arrFields As Variant
-
- Dim cnn As ADODB.Connection
- Set cnn = New ADODB.Connection
-
- myPath = "C:\Users\User\Desktop\test\database.xlsx"
- On Error GoTo errmsg
- cnn.Open "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" & myPath
-
- If cnn.State = 1 Then
- MsgBox 1
- Else
- MsgBox 2
- End If
-
- '关闭
- cnn.Close
- Set cnn = Nothing
- Exit Sub
- errmsg:
- MsgBox Err.Description, , "错误报告"
- End Sub
复制代码 按照上面程序试试,我测试是可以的。
|
|