我在从数据库缓存创建私有表时遇到问题,在set pt上获取错误1004并且不知道原因。
另外,你能告诉我在连接Access时如何避免验证窗口吗?
谢谢!
Sub Conectar()
Dim ws As Worksheet
Dim cn As WorkbookConnection
Dim pc As PivotCache
Dim pt As PivotTable
Dim cnString As String
cnString = "OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:\Users\sotogil\Documents\01_Inteligencia Comercial\02_MISTER RX/SELL IN Y RECETAS TOTAL (MS OKv2).accdb;Mode=Read;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";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 Compact=False;Jet OLEDB:Compact Without Replica Repair=False; Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False;Jet OLEDB:Bypass UserInfo Validation=False;Jet OLEDB:Limited DB Caching=False;Jet OLEDB:Bypass ChoiceField Validation=False"
Set cn = ThisWorkbook.Connections.Add( _
Name:="SELL IN - RECETAS", _
Description:="", _
ConnectionString:=cnString, _
CommandText:="BD SELL IN - RECETAS", _
lCmdtype:=XlCmdType.xlCmdTable)
Set pc = ThisWorkbook.PivotCaches.Create( _
SourceType:=xlExternal, _
SourceData:=cn)
Set ws = Worksheets.Add
Set pt = pc.CreatePivotTable( _
TableDestination:=ws.Range("C5"), _
TableName:="National")
End Sub