| Subject: Excel Routine |
| Group: microsoft.public.vstudio.general |
| Date: 6/3/2008 5:14:05 AM |
| From: =?Utf-8?B?TUVH?= [Email Address Protection] |
I'm trying to create an Excel 2007 Add-in using Visual Studio 2008. As a shortcut, I created a macro for a Pivot Table in Excel. I then copied it into Visual Studio. There are constants like (xldatabase, xlrowfield, etc) in the code. Visual Studio didn't like these. What do I need to include to get these constants. As a work-around, I debug.printed the values in Excel VBA and then inserted them at the start of the procedure. Here is the code (please feel free to offer any suggestions): Public Sub Build_Pivot_Table() Dim xlDatabase As Integer = 1 Dim xlExternal As Integer = 2 Dim xlPivotTableVersion12 As Integer = 3 Dim xlRowField As Integer = 1 Dim xlSum As Integer = -4157 Dim xlCount As Integer = -4112 Dim xlDescending As Integer = 2 Dim ws As Excel.Worksheet ws = Application.ActiveSheet ' Application.Worksheets.Add() Application.ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _ "Table_ExternalData_1", Version:=xlPivotTableVersion12).CreatePivotTable( _ TableDestination:="sheet4!R3C1", TableName:="PivotTable1", DefaultVersion _ :=xlPivotTableVersion12) Application.Worksheets("sheet4").Select() Application.Cells(3, 1).Select() With Application.ActiveSheet.PivotTables("PivotTable1").PivotFields("COMPANY") .Orientation = xlRowField .Position = 1 End With With Application.ActiveSheet.PivotTables("PivotTable1").PivotFields("NAME1") .Orientation = xlRowField .Position = 2 End With Application.ActiveSheet.PivotTables("PivotTable1").AddDataField(Application.ActiveSheet.PivotTables( _ "PivotTable1").PivotFields("DOCTOR"), "Counts", xlCount) End Sub Thanks, MEG |
| Back |