|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 nihao123456789 于 2023-4-6 09:34 编辑
Function OPENPATH(HDR As String, PATH As String)
Dim Conn1 As Object
Dim strconn As String
Set Conn1 = CreateObject("ADODB.Connection")
strconn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & PATH & ";Extended Properties='Excel 12.0;HDR=" & HDR & ";IMEX=1';" 'HDR=NO没有抬头,HDR=YES有抬头,IMEX=0写入,IMEX=1读取,IMEX=2可读可写
Conn1.Open strconn '打开数据库连接
End Function
Sub TEST()
Dim Connect1 As Object
Set Connect1 = CreateObject("ADODB.Connection")
Connect1 = OPENPATH("YES", "C:\工作簿1.XLSX")
Stop
End Sub
按这个,测试可以正常运行 |
|