IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

ajouter un titre à un graphique [XL-2013]


Sujet :

Macros et VBA Excel

  1. #1
    Membre averti
    Homme Profil pro
    Analyse système
    Inscrit en
    Février 2017
    Messages
    23
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Analyse système

    Informations forums :
    Inscription : Février 2017
    Messages : 23
    Par défaut ajouter un titre à un graphique
    Bonjour

    j'ai ecrit cette macro pour faire un graphique en dynamique a partir d une selection manuelle,

    cependant en arrivant à la définition du titre (phrase en gras dans le code)

    j'ai une erreur "Run time error -2147024809 (80070057) This object has no tittle" qui arrive ,

    si je mets cancel ça marche mais si j entre un nom pour le graphique ça marche pas,

    pouvez vous m aider please ;
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    Sub CreateChart()
        ' Create a new chart sheet from the table on Sheet2
        ' by using the Add method of the Charts collection.
        Dim objSelection As Range, objChart As Chart
        
        ' Select the sheet that contains the data.
        ActiveWorkbook.Sheets("TCD_VOL").Select
        
        ' Prompt the user to select the range to chart
        ' and set the Range object to the specified range.
        Set objSelection = _
            Application.InputBox(Prompt:="Select the columns and rows to chart", _
            Default:=Selection.Address, _
            Type:=8)
        
        ' Verify whether a selection was made.
        If objSelection.Cells.Count = 1 Then
            MsgBox "You must select at least one row or column for the chart range."
            Exit Sub
        End If
        
        ' Create a new chart sheet and specify its source data
        ' and appearance.
        Set objChart = Charts.Add
        With objChart
            .ChartType = xlColumnClustered
            '.SetSourceData objSelect
            .Location xlLocationAsNewSheet
            .Legend.Position = xlLegendPositionRight
            .PlotBy = xlColumns
        End With
        
        ' Ask the user whether to plot by rows instead.
        If MsgBox("Or plot by rows?", vbYesNo) = vbYes Then
            objChart.PlotBy = xlRows
        End If
        
        ' Prompt the user for a title.
        objChart.HasTitle = True
    objChart.ChartTitle.Text = InputBox("Title?")
        
        
        ' Ask the user whether to delete the chart.
        Application.DisplayAlerts = False
        If MsgBox("Delete chart?", vbYesNo) = vbYes Then
            ActiveSheet.Delete
        End If
        Application.DisplayAlerts = True
    End Sub

  2. #2
    Expert confirmé
    Homme Profil pro
    retraité
    Inscrit en
    Juin 2012
    Messages
    3 370
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : retraité
    Secteur : Associations - ONG

    Informations forums :
    Inscription : Juin 2012
    Messages : 3 370
    Par défaut
    Bonjour,
    Bizarre, pas de problème avec Excel 2010. Testé avec ce code.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    Sub ChartTitle()
        Dim objChart As Chart
        Set objChart = ActiveChart
        Debug.Print objChart.Name
        ' Prompt the user for a title.
        objChart.HasTitle = True
        objChart.ChartTitle.Text = InputBox("Title?")
        Set objChart = Nothing
    End Sub
    Bonne continuation.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. ajouter titre à un graphique
    Par ptitrault dans le forum Macros et VBA Excel
    Réponses: 0
    Dernier message: 05/10/2009, 11h51
  2. Ajout d'un titre à un graphique mvpart
    Par habasque dans le forum R
    Réponses: 1
    Dernier message: 23/06/2009, 10h48
  3. Ajouter des titres a une matrice
    Par sseneor dans le forum MATLAB
    Réponses: 8
    Dernier message: 24/04/2007, 20h13
  4. [carte graphique]ajout d'une carte graphique AGP 4x
    Par ghim dans le forum Composants
    Réponses: 4
    Dernier message: 09/03/2007, 09h27
  5. Ajouter dynamiquement un element graphique a un groupbox
    Par Revan777 dans le forum C++Builder
    Réponses: 2
    Dernier message: 07/11/2006, 14h09

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo