因此,我可以使用POST请求和MSXML2.ServerHTTP60对象从我们公司内的sharepoint站点下载.accdb文件,在Excel VBA中提供内部网密码等。酷!
使用下载的文件,我可以使用以下代码运行查询:
Dim connXXX As ADODB.Connection
Dim aQuery As String
Dim p As String
Dim res As Object
Dim connStr As String
p = ThisWorkbook.Path & "\testBASE1.accdb"
connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & p
aQuery = "SELECT Header1 FROM Table1 WHERE ID = 4"
Set connXXX = New ADODB.Connection
connXXX.Open connStr
Set res = connXXX.Execute(aQuery)
MsgBox res.Fields(0)
我真正想做的事情是完全下载文件,因此我可以针对托管在Intranet上的.accdb文件运行查询。
我一直在尝试使用.connectionString或输入" URL ="对此代码进行一些修改。而不是数据源......一切都无济于事;我无法弄清楚我将内网用户名/密码放在哪里...请帮忙!我总是在代码的connXXX.open部分得到我的错误。
1)这是否可能? 2)怎么样?!
代码破碎:
'ppp = "http://the_intranet_address_and_filename_with_extension"
'ppp = "URL=http://the_intranet_address_and_filename_with_extension"
'' I've tried both above
connStr = "Provider=Microsoft.ACE.OLEDB.12.0;"
aQuery = "SELECT Header1 FROM Table1 WHERE ID = 4"
connStrBig = connStr & "Data Source=" & ppp
connXXX.Provider = connStr
connXXX.ConnectionString = ppp
connXXX.Open
答案 0 :(得分:0)
通过VBA连接到受密码保护的Access数据库很棘手 - 我发现Microsoft建议的语法甚至不起作用......我已经获得DAO连接以使用受密码保护的DB,请参阅下面的代码 - 希望如此您可以使用相同的语法来处理ADO,或者只是一起切换:
Public Sub sampleCode()
Dim db As DAO.Database
Dim dbPath As String
Dim aQuery As String
Dim pword As String
Dim rs As DAO.Recordset
dbPath = ThisWorkbook.Path & "\testBASE1.accdb"
pword = "password"
aQuery = "SELECT Header1 FROM Table1 WHERE ID = 4"
Set db = Access.DBEngine.Workspaces(0).OpenDatabase(dbPath, True, False, ";PWD=" & pword)
Set rs = db.Execute(aQuery)
rs.MoveFirst
MsgBox rs.Fields(0)
End Sub
希望这有帮助, TheSilkCode