Conversion de macro excel 2007 en macro 2003

bill_test -  
Le Pingou Messages postés 12275 Date d'inscription   Statut Contributeur Dernière intervention   -
Bonjour,
J'ai réalisé une macro avec Excel 2007 qui fonctionne très bien.
Cependant, j'aimerais l'excécuter sous Excel 2003. mais je n'y arrive pas.
Ci-dessous mon code:

Sub attach()

Workbooks.Open Filename:= _
"C:\Subs.xls"

Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Report!r1C1:r8000C3", Version:=xlPivotTableVersion10).CreatePivotTable _
TableDestination:="Feuil1!r3C1", TableName:="Tableau croisé dynamique23", _
DefaultVersion:=xlPivotTableVersion10
Sheets("Feuil1").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("Tableau croisé dynamique23").PivotFields( _
"work")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("Tableau croisé dynamique23").PivotFields("Time")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("Tableau croisé dynamique23").PivotFields("Time")
.PivotItems("(vide)").Visible = False
End With

ActiveSheet.PivotTables("Tableau croisé dynamique23").AddDataField ActiveSheet. _
PivotTables("Tableau croisé dynamique23").PivotFields( _
"User"), "Somme de User", xlSum

Range("A176").Select
ActiveCell.FormulaR1C1 = "peak"
Windows("Subs").Activate

Range("A177").Select
ActiveCell.FormulaR1C1 = "=MAX(R[-172]C[21]:R[-5]C[21])"
Range("A177").Select
Selection.Copy
Windows("Rapport").Activate
Sheets("Mobility").Select
Range("I86").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows("Subs.xls").Activate

Range("H3").Select
Application.CutCopyMode = False
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("Feuil1!$A$3:$V$173")
ActiveWorkbook.ShowPivotChartActiveFields = True
ActiveChart.ApplyChartTemplate ("C:\text.crtx")
ActiveChart.ChartArea.Copy
Windows("Rappport.xls").Activate
Range("A65").Select
ActiveSheet.Paste

Windows("Subs.xls").Activate
ActiveWorkbook.Save
ActiveWindow.Close

End Sub

Merci de votre retour
Configuration: Windows XP Internet Explorer 7.0

5 réponses

  1. bill_test
     
    J'ai apporté quelques éléments de correction de la macro, ci-dessous la version qui marche sous Excel 2007:

    Sub attach()

    Workbooks.Open Filename:= _
    "C:\Subs.xls"

    Sheets.Add
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    "Report!r1C1:r8000C3", Version:=xlPivotTableVersion10).CreatePivotTable _
    TableDestination:="Feuil1!r3C1", TableName:="Tableau croisé dynamique23", _
    DefaultVersion:=xlPivotTableVersion10
    Sheets("Feuil1").Select
    Cells(3, 1).Select
    With ActiveSheet.PivotTables("Tableau croisé dynamique23").PivotFields( _
    "work")
    .Orientation = xlColumnField
    .Position = 1
    End With
    With ActiveSheet.PivotTables("Tableau croisé dynamique23").PivotFields("Time")
    .Orientation = xlRowField
    .Position = 1
    End With
    With ActiveSheet.PivotTables("Tableau croisé dynamique23").PivotFields("Time")
    .PivotItems("(vide)").Visible = False
    End With

    ActiveSheet.PivotTables("Tableau croisé dynamique23").AddDataField ActiveSheet. _
    PivotTables("Tableau croisé dynamique23").PivotFields( _
    "User"), "Somme de User", xlSum

    Range("A176").Select
    ActiveCell.FormulaR1C1 = "peak"
    Windows("Subs.xls").Activate

    Range("A177").Select
    ActiveCell.FormulaR1C1 = "=MAX(R[-172]C[21]:R[-5]C[21])"
    Range("A177").Select
    Selection.Copy
    Windows("Rapport.xls").Activate
    Sheets("test").Select
    Range("I20").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Windows("Subs.xls").Activate

    Range("H3").Select
    Application.CutCopyMode = False
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.SetSourceData Source:=Range("Feuil1!$A$3:$V$173")
    ActiveWorkbook.ShowPivotChartActiveFields = True
    ActiveChart.ApplyChartTemplate ("C:\text.crtx")
    ActiveChart.ChartArea.Copy
    Windows("Rapport.xls").Activate
    Range("A6").Select
    ActiveSheet.Paste

    Windows("Subs.xls").Activate
    ActiveWorkbook.Save
    ActiveWindow.Close

    End Sub

    Il affiche le message suivant au niveau de ActiveChart.ApplyChartTemplate ("C:\text.crtx")

    Erreur de compilation:

    Membre de méthode ou de données introuvable

    Merci pour votre aide.
    1
  2. Le Pingou Messages postés 12275 Date d'inscription   Statut Contributeur Dernière intervention   1 478
     
    Bonjour,
    Cette méthode ( ApplyChartTemplate) applique un type de graphique standard ou personnalisé à un graphique n'est pas prise en compte par Excel 2003.
    Essayez de neutraliser la ligne et voir si la procédure fonctionne!
    0
  3. Le Pingou Messages postés 12275 Date d'inscription   Statut Contributeur Dernière intervention   1 478
     
    Bonjour,
    J’ai mis le doigt sur un article qui devrait vous aider. https://excel.developpez.com/faq/?page=Graphique#ModeleGraph2007 , voir [ Nota
    Méthode pour Excel 2002] vers la fin.
    J’ai réalisé un essai en créant un graphique que j’ai enregistré sous « mongraphique » et voici la ligne de code que j’ai récupéré:
    ActiveChart.ApplyCustomType ChartType:=xlUserDefined, TypeName:= "mongraphique"
    "
    0
  4. Le Pingou Messages postés 12275 Date d'inscription   Statut Contributeur Dernière intervention   1 478
     
    Bonjour,
    Qu'elle est le message d'erreur sur 2003 et la ligne concernée !
    -1
  5. Vous n’avez pas trouvé la réponse que vous recherchez ?

    Posez votre question
  6. bill_test
     
    J'ai apporté quelques éléments de correction de la macro, ci-dessous la version qui marche sous Excel 2007:

    Sub attach()

    Workbooks.Open Filename:= _
    "C:\Subs.xls"

    Sheets.Add
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    "Report!r1C1:r8000C3", Version:=xlPivotTableVersion10).CreatePivotTable _
    TableDestination:="Feuil1!r3C1", TableName:="Tableau croisé dynamique23", _
    DefaultVersion:=xlPivotTableVersion10
    Sheets("Feuil1").Select
    Cells(3, 1).Select
    With ActiveSheet.PivotTables("Tableau croisé dynamique23").PivotFields( _
    "work")
    .Orientation = xlColumnField
    .Position = 1
    End With
    With ActiveSheet.PivotTables("Tableau croisé dynamique23").PivotFields("Time")
    .Orientation = xlRowField
    .Position = 1
    End With
    With ActiveSheet.PivotTables("Tableau croisé dynamique23").PivotFields("Time")
    .PivotItems("(vide)").Visible = False
    End With

    ActiveSheet.PivotTables("Tableau croisé dynamique23").AddDataField ActiveSheet. _
    PivotTables("Tableau croisé dynamique23").PivotFields( _
    "User"), "Somme de User", xlSum

    Range("A176").Select
    ActiveCell.FormulaR1C1 = "peak"
    Windows("Subs.xls").Activate

    Range("A177").Select
    ActiveCell.FormulaR1C1 = "=MAX(R[-172]C[21]:R[-5]C[21])"
    Range("A177").Select
    Selection.Copy
    Windows("Rapport.xls").Activate
    Sheets("test").Select
    Range("I20").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Windows("Subs.xls").Activate

    Range("H3").Select
    Application.CutCopyMode = False
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.SetSourceData Source:=Range("Feuil1!$A$3:$V$173")
    ActiveWorkbook.ShowPivotChartActiveFields = True
    ActiveChart.ApplyChartTemplate ("C:\text.crtx")
    ActiveChart.ChartArea.Copy
    Windows("Rapport.xls").Activate
    Range("A6").Select
    ActiveSheet.Paste

    Windows("Subs.xls").Activate
    ActiveWorkbook.Save
    ActiveWindow.Close

    End Sub

    Il affiche le message suivant au niveau de ActiveChart.ApplyChartTemplate ("C:\text.crtx")

    Erreur de compilation:

    Membre de méthode ou de données introuvable

    Merci pour votre aide.
    -1