Bonjour,
je viens solliciter l'aide d'expert de Macro sous Excel !
Je dois réaliser une macro dont voici les consignes :
A partir d’un classeur contenant un tableau de données, la macro doit construire 2 graphiques dont l’utilisateur choisira le type (Histogramme 3D ou barres 3D et un secteur 3D) et lancera l’impression rapide avec des paramètres précis.
Un ami m'a aidé à la réaliser, seulement je ne comprends pas à quel endroit je peux mettre en forme le graphique, c'est à dire changer les couleurs des quartiers ou des barres par exemple.
Voici le code :
Public choixGraph As String
Sub Commencer()
Form1.Show
End Sub
Sub TraceGraphs()
' Premier graphique
' Création
Charts.Add
If choixGraph = "1" Then
ActiveChart.ChartType = xl3DColumnClustered
Else
ActiveChart.ChartType = xl3DBarClustered
End If
With ActiveChart
.SetSourceData Source:=Sheets("Données").Range("A711"), PlotBy:=xlColumns 'Sheets(0): on prend tjrs la première feuille
.HasTitle = True
.ChartTitle.Characters.Text = "Réservations"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Nbre de réservation"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Trimestres"
End With
' Localisation
ActiveChart.Location Where:=xlLocationAsObject, Name:="Données"
With ActiveChart.Parent
.Height = 250
.Width = 360
.Top = 210
.Left = 0
End With
' Deuxième graphique
' Création
Charts.Add
With ActiveChart
.ChartType = xl3DPie
.SetSourceData Source:=Sheets("Données").Range("A711"), PlotBy:=xlColumns 'Sheets(0): on prend tjrs la première feuille
.HasTitle = True
.ChartTitle.Characters.Text = "Proportion de reservation"
End With
' Localisation
ActiveChart.Location Where:=xlLocationAsObject, Name:="Données"
With ActiveChart.Parent
.Height = 250
.Width = 360
.Top = 210
.Left = 360
End With
' Ensuite, on demande si on veut imprimer, si l'utilisateur dit 'non' on arrête la procédure
' à ce moment pour ne pas exécuter le code d'après
If MsgBox("Voulez-vous imprimer la feuille ?", vbYesNo) = vbNo Then
Exit Sub
End If
Sheets("Données").Range("A1").Select
Call Impression
End Sub
Sub Impression()
'
' MacroImp Macro
'
'
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
ActiveSheet.PageSetup.PrintArea = ""
With ActiveSheet.PageSetup
.LeftHeader = "&F"
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = "Confidentiel"
.CenterFooter = "&D"
.RightFooter = "&P"
.LeftMargin = Application.InchesToPoints(0.393700787401575)
.RightMargin = Application.InchesToPoints(0.393700787401575)
.TopMargin = Application.InchesToPoints(0.393700787401575)
.BottomMargin = Application.InchesToPoints(0.393700787401575)
.HeaderMargin = Application.InchesToPoints(0.31496062992126)
.FooterMargin = Application.InchesToPoints(0.31496062992126)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
.PrintErrors = xlPrintErrorsDisplayed
End With
ActiveWindow.SelectedSheets.PrintPreview
ActiveWindow.SelectedSheets.PrintOut Copies:=2
MsgBox ("Impression réussie avec succès")
End Sub
J'espère que quelqu'un pourra m'expliquer comment faire
Merci par avance !
je viens solliciter l'aide d'expert de Macro sous Excel !
Je dois réaliser une macro dont voici les consignes :
A partir d’un classeur contenant un tableau de données, la macro doit construire 2 graphiques dont l’utilisateur choisira le type (Histogramme 3D ou barres 3D et un secteur 3D) et lancera l’impression rapide avec des paramètres précis.
Un ami m'a aidé à la réaliser, seulement je ne comprends pas à quel endroit je peux mettre en forme le graphique, c'est à dire changer les couleurs des quartiers ou des barres par exemple.
Voici le code :
Public choixGraph As String
Sub Commencer()
Form1.Show
End Sub
Sub TraceGraphs()
' Premier graphique
' Création
Charts.Add
If choixGraph = "1" Then
ActiveChart.ChartType = xl3DColumnClustered
Else
ActiveChart.ChartType = xl3DBarClustered
End If
With ActiveChart
.SetSourceData Source:=Sheets("Données").Range("A711"), PlotBy:=xlColumns 'Sheets(0): on prend tjrs la première feuille
.HasTitle = True
.ChartTitle.Characters.Text = "Réservations"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Nbre de réservation"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Trimestres"
End With
' Localisation
ActiveChart.Location Where:=xlLocationAsObject, Name:="Données"
With ActiveChart.Parent
.Height = 250
.Width = 360
.Top = 210
.Left = 0
End With
' Deuxième graphique
' Création
Charts.Add
With ActiveChart
.ChartType = xl3DPie
.SetSourceData Source:=Sheets("Données").Range("A711"), PlotBy:=xlColumns 'Sheets(0): on prend tjrs la première feuille
.HasTitle = True
.ChartTitle.Characters.Text = "Proportion de reservation"
End With
' Localisation
ActiveChart.Location Where:=xlLocationAsObject, Name:="Données"
With ActiveChart.Parent
.Height = 250
.Width = 360
.Top = 210
.Left = 360
End With
' Ensuite, on demande si on veut imprimer, si l'utilisateur dit 'non' on arrête la procédure
' à ce moment pour ne pas exécuter le code d'après
If MsgBox("Voulez-vous imprimer la feuille ?", vbYesNo) = vbNo Then
Exit Sub
End If
Sheets("Données").Range("A1").Select
Call Impression
End Sub
Sub Impression()
'
' MacroImp Macro
'
'
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
ActiveSheet.PageSetup.PrintArea = ""
With ActiveSheet.PageSetup
.LeftHeader = "&F"
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = "Confidentiel"
.CenterFooter = "&D"
.RightFooter = "&P"
.LeftMargin = Application.InchesToPoints(0.393700787401575)
.RightMargin = Application.InchesToPoints(0.393700787401575)
.TopMargin = Application.InchesToPoints(0.393700787401575)
.BottomMargin = Application.InchesToPoints(0.393700787401575)
.HeaderMargin = Application.InchesToPoints(0.31496062992126)
.FooterMargin = Application.InchesToPoints(0.31496062992126)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
.PrintErrors = xlPrintErrorsDisplayed
End With
ActiveWindow.SelectedSheets.PrintPreview
ActiveWindow.SelectedSheets.PrintOut Copies:=2
MsgBox ("Impression réussie avec succès")
End Sub
J'espère que quelqu'un pourra m'expliquer comment faire
Merci par avance !