Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Excel > Macros et VBA Excel
Macros et VBA Excel Vos questions relatives aux macros Excel, à l'utilisation de VBA et à l'automatisation de vos classeurs Excel.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 24/01/2012, 09h40   #1
Membre habitué
 
Avatar de fowlie
 
Étudiant
Inscription : mai 2011
Messages : 335
Détails du profil
Informations personnelles :
Localisation : France

Informations professionnelles :
Activité : Étudiant
Secteur : Industrie

Informations forums :
Inscription : mai 2011
Messages : 335
Points : 146
Points : 146
Bonjour le forum,

Dans mon userform j'ai mis une image. Cette image et en fait une copie d'un graphique que je créer sur excel. Le problème est que je n'arrive pas à dimensionner l'image du graphique. Je ne suis peut-être pas clair.

Ma fonction créer un graphe. Pour l'afficher dans mon useform je le copie dans un dossier en tant qu'image et je charge cette image dans mon userform. C'est la seule méthode que j'ai trouvé. elle fonctionne trés bien. Mais je n'arrive pas à redimensionner le graphe. Je pense qu'il faut le redimensionner avant de l'enregistrer dans un fichier .. mais je n'ai pas trouvé le bon code.

Code :
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Function grapheAchat()
    Charts.Add
    ActiveChart.ChartType = xl3DPie
    ActiveChart.SetSourceData Source:=Sheets("Calcul Délai").Range( _
        "C14:E14,C2:E2")
    ActiveChart.Location Where:=xlLocationAsObject, name:="Calcul Délai"
 
    ActiveChart.SeriesCollection(1).ApplyDataLabels AutoText:=True, LegendKey:= _
    False, HasLeaderLines:=True, ShowSeriesName:=False, ShowCategoryName:= _
    False, ShowValue:=True, ShowPercentage:=False, ShowBubbleSize:=False
    ActiveChart.SeriesCollection(1).DataLabels.Select
    With Selection.Font
        .FontStyle = "Gras"
        .Size = 14
    End With
    ActiveChart.SeriesCollection(1).DataLabels.Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .ReadingOrder = xlContext
        .Position = xlLabelPositionCenter
        .Orientation = xlHorizontal
    End With
 
    ActiveChart.SeriesCollection(1).Points(3).Select
    With Selection.Border
        .Weight = xlThin
        .LineStyle = xlAutomatic
    End With
    With Selection.Interior
        .ColorIndex = 5
        .Pattern = xlSolid
    End With
    ActiveChart.SeriesCollection(1).Points(2).Select
    With Selection.Border
        .Weight = xlThin
        .LineStyle = xlAutomatic
    End With
    With Selection.Interior
        .ColorIndex = 4
        .Pattern = xlSolid
    End With
    ActiveChart.SeriesCollection(1).Points(1).Select
    With Selection.Border
        .Weight = xlThin
        .LineStyle = xlAutomatic
    End With
    With Selection.Interior
        .ColorIndex = 3
        .Pattern = xlSolid
    End With
    With ActiveChart
        .HasTitle = True
        .ChartTitle.Characters.Text = "grph"
    End With
 
    Dim Grph As Chart
    Set Grph = ActiveChart
    Grph.Export Filename:="C:\Temp\Grph.jpg", filtername:="JPG"
    StatUsine.Image1.Picture = LoadPicture("C:\Temp\Grph.jpg")
    Sheets("Calcul délai").ChartObjects(1).Delete
 
End Function
J'ai essayé d'enregistré une macro dans laquelle j'agrandis mon graphe et j'obtiens :

Code :
1
2
3
4
    ActiveSheet.Shapes("Graphique 366").ScaleWidth 1.16, msoFalse, _
        msoScaleFromBottomRight
    ActiveSheet.Shapes("Graphique 366").ScaleHeight 1.41, msoFalse, _
        msoScaleFromBottomRight
Cependant je n'arrive pas à l'adapter à ce dont j'ai besoin, mon graphique ne s'appelant pas "Graphique 366", en fait je ne lui donne pas de nom dans ma fonction.

Que dois-je utiliser?
Merci pour votre aide
__________________
---Fowlie---
fowlie est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/01/2012, 17h42   #2
Expert Confirmé Sénior
 
Homme Daniel
aucune
Inscription : septembre 2011
Messages : 2 004
Détails du profil
Informations personnelles :
Nom : Homme Daniel
Localisation : France, Seine et Marne (Île de France)

Informations professionnelles :
Activité : aucune

Informations forums :
Inscription : septembre 2011
Messages : 2 004
Points : 4 035
Points : 4 035
Les paramètres sont dans "LoadPicture" :
LoadPicture(Fichier,Largeur, Hauteur)
Par exemple :

Code :
Me.Image1.Picture = LoadPicture("c:\temp\ch.jpg", 900, 600)
__________________
Cordialement.

Daniel

Citation:
La plus perdue de toutes les journées est celle où l'on n'a pas ri.
Chamfort
Daniel.C est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/01/2012, 08h48   #3
Membre habitué
 
Avatar de fowlie
 
Étudiant
Inscription : mai 2011
Messages : 335
Détails du profil
Informations personnelles :
Localisation : France

Informations professionnelles :
Activité : Étudiant
Secteur : Industrie

Informations forums :
Inscription : mai 2011
Messages : 335
Points : 146
Points : 146
Merci pour ce conseil, mais malheureusement j'ai testé plusieurs valeurs et ça ne marche pas. Ne faut-il pas choisir la taille avant d'enregistrer le graphe dans le dossier temporaire, et de la charger ensuite dans le userForm?
__________________
---Fowlie---
fowlie est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/01/2012, 10h11   #4
Expert Confirmé Sénior
 
Homme Daniel
aucune
Inscription : septembre 2011
Messages : 2 004
Détails du profil
Informations personnelles :
Nom : Homme Daniel
Localisation : France, Seine et Marne (Île de France)

Informations professionnelles :
Activité : aucune

Informations forums :
Inscription : septembre 2011
Messages : 2 004
Points : 4 035
Points : 4 035
Ça fonctionne ici. Quelle est ta version d'Excel (tu devrais l'indiquer systématiquement dans le titre du message) ?
Et poste si tu le peux un classeur exemple.
__________________
Cordialement.

Daniel

Citation:
La plus perdue de toutes les journées est celle où l'on n'a pas ri.
Chamfort
Daniel.C est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/01/2012, 10h45   #5
Membre habitué
 
Avatar de fowlie
 
Étudiant
Inscription : mai 2011
Messages : 335
Détails du profil
Informations personnelles :
Localisation : France

Informations professionnelles :
Activité : Étudiant
Secteur : Industrie

Informations forums :
Inscription : mai 2011
Messages : 335
Points : 146
Points : 146
Je travaille sous excel 2003, mais j'ai besoin que mon projet s'adapte à 2007 et 2010 ...

Je ne peux pas envoyer de classeur, désolé ..

Mais je peux essayer de mieux m'expliquer.

J'ai créer un userform avec une "zone image" à l'intérieur
Dans ma feuille excel j'ai un tableau de ce type :

En cours Terminé Abandon
2 3 5

Sur cette même feuille j'ai un bouton, celui-ci permet d'afficher mon userform avec le code suivant :
Code :
1
2
Application.Run (grapheAchat)
            Stat.Show
Stat étant le nom de mon userform et grapheAchat étant une fonction qui me permet de créer le graphe, de l'enregistrer puis de le charger en tant qu'image dans mon userform, en voici le code :
Code :
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Function grapheAchat()
    Charts.Add
    ActiveChart.ChartType = xl3DPie
    ActiveChart.SetSourceData Source:=Sheets("Calcul Délai").Range( _
        "C14:E14,C2:E2")
    ActiveChart.Location Where:=xlLocationAsObject, name:="Calcul Délai"
 
    ActiveChart.SeriesCollection(1).ApplyDataLabels AutoText:=True, LegendKey:= _
    False, HasLeaderLines:=True, ShowSeriesName:=False, ShowCategoryName:= _
    False, ShowValue:=True, ShowPercentage:=False, ShowBubbleSize:=False
    ActiveChart.SeriesCollection(1).DataLabels.Select
    With Selection.Font
        .FontStyle = "Gras"
        .Size = 14
    End With
    ActiveChart.SeriesCollection(1).DataLabels.Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .ReadingOrder = xlContext
        .Position = xlLabelPositionCenter
        .Orientation = xlHorizontal
    End With
 
    ActiveChart.SeriesCollection(1).Points(3).Select
    With Selection.Border
        .Weight = xlThin
        .LineStyle = xlAutomatic
    End With
    With Selection.Interior
        .ColorIndex = 5
        .Pattern = xlSolid
    End With
    ActiveChart.SeriesCollection(1).Points(2).Select
    With Selection.Border
        .Weight = xlThin
        .LineStyle = xlAutomatic
    End With
    With Selection.Interior
        .ColorIndex = 4
        .Pattern = xlSolid
    End With
    ActiveChart.SeriesCollection(1).Points(1).Select
    With Selection.Border
        .Weight = xlThin
        .LineStyle = xlAutomatic
    End With
    With Selection.Interior
        .ColorIndex = 3
        .Pattern = xlSolid
    End With
    With ActiveChart
        .HasTitle = True
        .ChartTitle.Characters.Text = "grph"
    End With
 
    Dim Grph As Chart
    Set Grph = ActiveChart
    Grph.Export Filename:="U:\LEAN\Stagiaires\Julie\Grph.jpg", filtername:="JPG"
    Stat.Image1.Picture = LoadPicture("C:\Temp\Grph.jpg", 550, 400)
    Sheets("Calcul délai").ChartObjects(1).Delete
 
End Function
J'ai essayé de mettre la ligne
Code :
 Stat.Image1.Picture = LoadPicture("C:\Temp\Grph.jpg", 550, 400)
dans le userform_initializing en remplaçant Stat par Me mais ça n'a rien changé ...
__________________
---Fowlie---
fowlie est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/01/2012, 08h14   #6
Membre habitué
 
Avatar de fowlie
 
Étudiant
Inscription : mai 2011
Messages : 335
Détails du profil
Informations personnelles :
Localisation : France

Informations professionnelles :
Activité : Étudiant
Secteur : Industrie

Informations forums :
Inscription : mai 2011
Messages : 335
Points : 146
Points : 146
Il n'y a pas d'autres moyens d'augmenter la taille que l'utilisation de LoadPicture?
Personne n'a d'idée sur mon problème?

Merci d'avance
__________________
---Fowlie---
fowlie est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/01/2012, 10h02   #7
Expert Confirmé Sénior
 
Homme Daniel
aucune
Inscription : septembre 2011
Messages : 2 004
Détails du profil
Informations personnelles :
Nom : Homme Daniel
Localisation : France, Seine et Marne (Île de France)

Informations professionnelles :
Activité : aucune

Informations forums :
Inscription : septembre 2011
Messages : 2 004
Points : 4 035
Points : 4 035
Ce n'at pas avec "LoadPicture. Regarde :

Code :
Me.Image1.PictureSizeMode = fmPictureSizeModeStretch
Regarde les différentes valeurs de "PictureSizeMode"
__________________
Cordialement.

Daniel

Citation:
La plus perdue de toutes les journées est celle où l'on n'a pas ri.
Chamfort
Daniel.C est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 26/01/2012, 14h02   #8
Membre habitué
 
Avatar de fowlie
 
Étudiant
Inscription : mai 2011
Messages : 335
Détails du profil
Informations personnelles :
Localisation : France

Informations professionnelles :
Activité : Étudiant
Secteur : Industrie

Informations forums :
Inscription : mai 2011
Messages : 335
Points : 146
Points : 146
Ah merci =D effectivement ça s'adapte à la taille de la zone image.

Par contre mon image étant agrandie, elle est un peu floue, enfin je peux avancer avec ça, mais est-il possible d'agrandir le graphe avant de l'enregistrer en jpeg, afin de le charger directement à la bonne taille?

J'ai peut-être trouvé une solution, en utilisant ce code j'arrive à modifier la taille du graphique :
Code :
1
2
3
4
    ActiveSheet.Shapes(ActiveSheet.Shapes.Count).ScaleWidth 1.3, msoFalse, _
        msoScaleFromBottomRight
    ActiveSheet.Shapes(ActiveSheet.Shapes.Count).ScaleHeight 1.15, msoFalse, _
        msoScaleFromBottomRight
Mais je n'arrive pas à trouver les bonnes dimensions, que représente exactement les chiffres 1.3 et 1.15? j'agrandis la largeur de 30% et la hauteur de 15% c'est ça?
__________________
---Fowlie---
fowlie est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/01/2012, 17h23   #9
Expert Confirmé Sénior
 
Homme Daniel
aucune
Inscription : septembre 2011
Messages : 2 004
Détails du profil
Informations personnelles :
Nom : Homme Daniel
Localisation : France, Seine et Marne (Île de France)

Informations professionnelles :
Activité : aucune

Informations forums :
Inscription : septembre 2011
Messages : 2 004
Points : 4 035
Points : 4 035
Oui, ou tu peux aussi utiliser :


Code :
1
2
3
4
5
    With ActiveSheet.Shapes(ActiveSheet.Shapes.Count)
        .LockAspectRatio = msoTrue
        .ScaleHeight 1.15, msoFalse, _
            msoScaleFromBottomRight
    End With
"LockAspectRatio" conserve les proportions hauteur / largeur.
__________________
Cordialement.

Daniel

Citation:
La plus perdue de toutes les journées est celle où l'on n'a pas ri.
Chamfort
Daniel.C est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/01/2012, 08h14   #10
Membre habitué
 
Avatar de fowlie
 
Étudiant
Inscription : mai 2011
Messages : 335
Détails du profil
Informations personnelles :
Localisation : France

Informations professionnelles :
Activité : Étudiant
Secteur : Industrie

Informations forums :
Inscription : mai 2011
Messages : 335
Points : 146
Points : 146
Merci beaucoup pour l'info et pour l'aide
__________________
---Fowlie---
fowlie est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 20h23.


 
 
 
 
Partenaires

Hébergement Web