|
I'm trying to create a new Pivot table in a workbook with VSTO2.
The second line crash:
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Server stack trace: Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at Microsoft.Office.Interop.Excel.PivotCaches.Add(XlPivotTableSourceType SourceType, Object SourceData) at ExcelTestPivot.ThisWorkbook.ThisWorkbook_Startup(Object sender, EventArgs e) in C:\Documents and Settings\****\ThisWorkbook.vb:line 11
Can you hel me? Thnks.
Here the code:
Dim oPiv As Excel.PivotCache
oPiv = Me.PivotCaches.Add(Excel.XlPivotTableSourceType.xlDatabase)
With oPiv
.Connection = "Data Source=.\SQLEXPRESS;Initial Catalog=exlCantieri;Integrated Security=True"
.CommandType = Excel.XlCmdType.xlCmdSql
.CommandText = "SELECT *** FROM ***"
.CreatePivotTable(TableDestination:="", TableName:="Tabella_pivot1", _
DefaultVersion:=Excel.XlPivotTableVersionList.xlPivotTableVersion10)
End With
Globals.ThisWorkbook.PivotTableWizard(TableDestination:=Globals.Foglio1.Cells(3, 1))
Globals.Foglio1.Cells(3, 1).Select()
With Globals.Foglio1.PivotTables("Tabella_pivot1").PivotFields("field1")
.Orientation = Excel.XlPivotFieldOrientation.xlRowField
.Position = 1
End With
With Globals.Foglio1.PivotTables("Tabella_pivot1").PivotFields("field2")
.Orientation = Excel.XlPivotFieldOrientation.xlColumnField
.Position = 1
End With
Globals.Foglio1.Range( "B4").Select()
Globals.Foglio1.PivotTables( "Tabella_pivot1").PivotCache.Refresh()
paolo |