Conversion de macro excel 2007 en macro 2003

Fermé
bill_test - 3 sept. 2009 à 15:46
Le Pingou Messages postés 12242 Date d'inscription mercredi 11 août 2004 Statut Contributeur Dernière intervention 16 mars 2025 - 4 sept. 2009 à 17:12
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
A voir également:

5 réponses

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
Le Pingou Messages postés 12242 Date d'inscription mercredi 11 août 2004 Statut Contributeur Dernière intervention 16 mars 2025 1 458
4 sept. 2009 à 15:47
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
Le Pingou Messages postés 12242 Date d'inscription mercredi 11 août 2004 Statut Contributeur Dernière intervention 16 mars 2025 1 458
4 sept. 2009 à 17:12
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
Le Pingou Messages postés 12242 Date d'inscription mercredi 11 août 2004 Statut Contributeur Dernière intervention 16 mars 2025 1 458
3 sept. 2009 à 23:21
Bonjour,
Qu'elle est le message d'erreur sur 2003 et la ligne concernée !
-1

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
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