Excel Macro Runtime error 428 in Excel 2003

Posted by Adam on Stack Overflow See other posts from Stack Overflow or by Adam
Published on 2010-06-17T14:20:55Z Indexed on 2010/06/17 14:23 UTC
Read the original article Hit count: 491

Filed under:
|
|

Hi

I have created a xlt excel template which works fine in Excel 2007 under compatibility mode and shows no errors on compatibility check. The template runs a number of Macros which creates pivot tables and charts.

When a colleague tries to run the same xlt on excel 2003 they get a Runtime error 428 (Object does not support this property or method).

The runtime error fails at this point;

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    "raw!R1C1:R65536C37", Version:=xlPivotTableVersion10).CreatePivotTable _
    TableDestination:="Frontpage!R7C1", TableName:="PivotTable2", _
    DefaultVersion:=xlPivotTableVersion10

Any help would be appreciated.

This is the full Macro;

    Sub Auto_Open()
'
' ImportData Macro
' Macro to import data, Data must be in your local D: Drive and named raw.csv
'

'
    Sheets("raw").Select
    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;d:\raw.csv", Destination:=Range _
        ("$A$1"))
        .Name = "raw_1"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 850
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
'
' AddMonthColumn Macro
'
'
    Sheets("raw").Select
    Range("AK1").Select
    ActiveCell.FormulaR1C1 = "Month"
    Range("AK2").FormulaR1C1 = "=DATE(YEAR(RC[-36]),MONTH(RC[-36]),1)"
    LastRow = ActiveSheet.UsedRange.Rows.Count
    Range("AK2").AutoFill Destination:=Range("AK2:AK" & LastRow)
    Columns("AK:AK").EntireColumn.AutoFit
    Columns("AK:AK").Select
    Selection.NumberFormat = "mmmm"
    With Selection
        .HorizontalAlignment = xlCenter
    End With
    Columns("AK:AK").EntireColumn.AutoFit
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
'
' Add Report Information [Text]
'
    Sheets("Frontpage").Select
    Range("A2:N2").Select
    Selection.Merge
    ActiveCell.FormulaR1C1 = "Service Activity Report"
    With Selection.Font
        .Size = 20
    End With
    Range("A3:N3").Select
    Selection.Merge
    ActiveCell.FormulaR1C1 = InputBox("Customer Name")
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
        End With
    Range("A4:N4").Select
    Selection.Merge
    ActiveCell.FormulaR1C1 = InputBox("Date Range dd/mm/yyyy - dd/mm/yyyy")
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
        End With
'
' IncidentsbyPriority Macro
'

'
    Sheets("Frontpage").Select
    Range("A7").Select
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "raw!R1C1:R65536C37", Version:=xlPivotTableVersion10).CreatePivotTable _
        TableDestination:="Frontpage!R7C1", TableName:="PivotTable2", _
        DefaultVersion:=xlPivotTableVersion10
    Sheets("Frontpage").Select
    Cells(7, 1).Select
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.SetSourceData Source:=Range("Frontpage!$A$7:$H$22")
    ActiveChart.ChartType = xlColumnClustered
    With ActiveSheet.PivotTables("PivotTable2").PivotFields("Priority")
        .Orientation = xlRowField
        .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
        "PivotTable2").PivotFields("Case ID"), "Count of Case ID", xlCount
    ActiveChart.Parent.Name = "IncidentsbyPriority"
    ActiveChart.ChartTitle.Text = "Incidents by Priority"
    Dim RngToCover As Range
    Dim ChtOb As ChartObject
    Set RngToCover = ActiveSheet.Range("D7:L16")
    Set ChtOb = ActiveSheet.ChartObjects("IncidentsbyPriority")
    ChtOb.Height = RngToCover.Height ' resize
    ChtOb.Width = RngToCover.Width ' resize
    ChtOb.Top = RngToCover.Top ' reposition
    ChtOb.Left = RngToCover.Left ' reposition
'
' IncidentbyMonth Macro
'

'
    Sheets("Frontpage").Select
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "raw!R1C1:R65536C37", Version:=xlPivotTableVersion10).CreatePivotTable _
        TableDestination:="Frontpage!R18C1", TableName:="PivotTable4", _
        DefaultVersion:=xlPivotTableVersion10
    Sheets("Frontpage").Select
    Cells(18, 1).Select
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.SetSourceData Source:=Range("Frontpage!$A$18:$H$38")
    ActiveChart.ChartType = xlColumnClustered
    With ActiveSheet.PivotTables("PivotTable4").PivotFields("Month")
        .Orientation = xlRowField
        .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable4").AddDataField ActiveSheet.PivotTables( _
        "PivotTable4").PivotFields("Case ID"), "Count of Case ID", xlCount
    ActiveChart.Parent.Name = "IncidentbyMonth"
    ActiveChart.ChartTitle.Text = "Incidents by Month"
    Dim RngToCover2 As Range
    Dim ChtOb2 As ChartObject
    Set RngToCover2 = ActiveSheet.Range("D18:L30")
    Set ChtOb2 = ActiveSheet.ChartObjects("IncidentbyMonth")
    ChtOb2.Height = RngToCover2.Height ' resize
    ChtOb2.Width = RngToCover2.Width ' resize
    ChtOb2.Top = RngToCover2.Top ' reposition
    ChtOb2.Left = RngToCover2.Left ' reposition

'
' IncidentbyCategory Macro
'

'
    Sheets("Frontpage").Select
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "raw!R1C1:R65536C37", Version:=xlPivotTableVersion10).CreatePivotTable _
        TableDestination:="Frontpage!R38C1", TableName:="PivotTable6", _
        DefaultVersion:=xlPivotTableVersion10
    Sheets("Frontpage").Select
    Cells(38, 1).Select
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.SetSourceData Source:=Range("Frontpage!$A$38:$H$119")
    ActiveChart.ChartType = xlColumnClustered
    With ActiveSheet.PivotTables("PivotTable6").PivotFields("Category 2")
        .Orientation = xlRowField
        .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable6").PivotFields("Category 3")
        .Orientation = xlPageField
        .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable6").AddDataField ActiveSheet.PivotTables( _
        "PivotTable6").PivotFields("Case ID"), "Count of Case ID", xlCount
    ActiveChart.Parent.Name = "IncidentbyCategory"
    ActiveChart.ChartTitle.Text = "Incidents by Category"
    Dim RngToCover3 As Range
    Dim ChtOb3 As ChartObject
    Set RngToCover3 = ActiveSheet.Range("D38:L56")
    Set ChtOb3 = ActiveSheet.ChartObjects("IncidentbyCategory")
    ChtOb3.Height = RngToCover3.Height ' resize
    ChtOb3.Width = RngToCover3.Width ' resize
    ChtOb3.Top = RngToCover3.Top ' reposition
    ChtOb3.Left = RngToCover3.Left ' reposition
'
' IncidentsbySiteandPriority Macro
'

'
    Sheets("Frontpage").Select
    Range("A71").Select
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "raw!R1C1:R65536C37", Version:=xlPivotTableVersion10).CreatePivotTable _
        TableDestination:="Frontpage!R71C1", TableName:="PivotTable3", _
        DefaultVersion:=xlPivotTableVersion10
    Sheets("Frontpage").Select
    Cells(71, 1).Select
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.SetSourceData Source:=Range("Frontpage!$A$71:$H$90")
    ActiveChart.ChartType = xlColumnClustered
    With ActiveSheet.PivotTables("PivotTable3").PivotFields("Site Name")
        .Orientation = xlRowField
        .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable3").PivotFields("Priority")
        .Orientation = xlColumnField
        .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
        "PivotTable3").PivotFields("Case ID"), "Count of Case ID", xlCount
    ActiveChart.Parent.Name = "IncidentbySiteandPriority"
'    ActiveChart.ChartTitle.Text = "Incidents by Site and Priority"
    Dim RngToCover4 As Range
    Dim ChtOb4 As ChartObject
    Set RngToCover4 = ActiveSheet.Range("H71:O91")
    Set ChtOb4 = ActiveSheet.ChartObjects("IncidentbySiteandPriority")
    ChtOb4.Height = RngToCover4.Height ' resize
    ChtOb4.Width = RngToCover4.Width ' resize
    ChtOb4.Top = RngToCover4.Top ' reposition
    ChtOb4.Left = RngToCover4.Left ' reposition
    Columns("A:G").Select
    Range("A52").Activate
    Columns("A:G").EntireColumn.AutoFit

End Sub

© Stack Overflow or respective owner

Related posts about excel

Related posts about excel-vba