|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
请问我当前Excel透视表的数据源为一个access数据库当中的表,现在我想更换为另外一个新的数据库作为数据源,应该怎么写呢?
录的宏改了改,但是数据源没有变
- Private Sub 修改需要连接的数据库()
- ' tool = ThisWorkbook.Name
- Sheets("目录").Select
- dbName = Range("J3")
- dtName = Range("J4")
- DataSource = ThisWorkbook.Path & "" & dbName & ".accdb"
- pt = "数据透视表3"
-
- ThisWorkbook.Connections.Add2 dbName, "", _
- Array( _
- "OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Password="""";User ID=Admin;Data Source=" & DataSource & ";Mode=Share Deny Writ" _
- , _
- "e;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine" _
- , _
- " Type=6;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New" _
- , _
- " Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Com" _
- , _
- "pact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False;Jet OLEDB:Byp" _
- , _
- "ass UserInfo Validation=False;Jet OLEDB:Limited DB Caching=False;Jet OLEDB:Bypass ChoiceField Validation=False" _
- ), dtName, 3
-
-
- For Each Sheet In Sheets
- On Error Resume Next
- Sheet.PivotTables(pt).ChangeConnection ActiveWorkbook.Connections(dbName)
- Next
-
- End Sub
复制代码
|
|