Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Word > VBA Word
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 25/04/2007, 11h33   #1
Nouveau Membre du Club
 
Inscription : avril 2007
Messages : 116
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 116
Points : 25
Points : 25
Par défaut [VBA-W]Insertion graphique excel

Mon VBA ne me reconnait pas la fonction "ChartObjects" pourquoi?
Merci
dev81 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/04/2007, 11h49   #2
Inactif
 
Avatar de ouskel'n'or
 
Inscription : février 2005
Messages : 12 466
Détails du profil
Informations forums :
Inscription : février 2005
Messages : 12 466
Points : 11 930
Points : 11 930
Citation:
Envoyé par dev81
Mon VBA ne me reconnait pas la fonction "ChartObjects" pourquoi?
Merci
Oui, et ça risque de durer longtemps comme ça si tu ne nous mets pas ton code
Tu fais ça ?
A+
ouskel'n'or est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/04/2007, 11h52   #3
Nouveau Membre du Club
 
Inscription : avril 2007
Messages : 116
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 116
Points : 25
Points : 25
Le voila

Y a t il une reference particuliere à part celle d'excel à cocher?

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
Sub InsérerGraphExcel(Path As String)
    Dim XlAppli As Object
    Dim XlCl As Workbook
    Dim Xlfl As Worksheet
    Set XlAppli = CreateObject("Excel.Application") '< L'appli Excel
    Set XlCl = XlAppli.Workbooks.Open(Path) '< le classeur
    Set Xlfl = XlCl.Worksheets("Evol Etat f") '< la feuille
'    With Xlfl
'        .Range("").Copy ' < La Plage
'    End With
 
    XlAppli.ActiveSheet.ChartObjects(1).Activate
    ' Select the chart.
    XlAppli.ActiveChart.ChartArea.Select
    ' Copy the chart.
    XlAppli.ActiveChart.ChartArea.Copy
 
 
 
    On Error Resume Next
    'Colle la plage Excel avec liaison à l'emplacement du curseur
    Selection.PasteSpecial Link:=True, DataType:=wdPasteOLEObject, Placement:= _
        wdInLine, DisplayAsIcon:=False
    DoEvents
    XlCl.Close False
    XlAppli.Quit
    Set XlAppli = Nothing
    Set XlCl = Nothing
    Set Xlfl = Nothing
End Sub
dev81 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/04/2007, 14h25   #4
Nouveau Membre du Club
 
Inscription : avril 2007
Messages : 116
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 116
Points : 25
Points : 25
Comment on utilise les "ChartObjects"?
dev81 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/04/2007, 14h53   #5
Nouveau Membre du Club
 
Inscription : avril 2007
Messages : 116
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 116
Points : 25
Points : 25
J'ai trouvé une erreur mais maintenant j'ai un problème avec la selection du graphique.

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
Sub InsérerGraphExcel(Path As String)
    Dim XlAppli As Object
    Dim XlCl As Workbook
    Dim Xlfl As Worksheet
    Set XlAppli = CreateObject("Excel.Application") '< L'appli Excel
    Set XlCl = XlAppli.Workbooks.Open(Path) '< le classeur
    Set Xlfl = XlCl.Worksheets("Sheet1") '< la feuille


    Xlfl.ChartObjects(1).Activate
    ' Select the chart.
    Xlfl.ActiveChart.ChartArea.Select
    ' Copy the chart.
    Xlfl.ActiveChart.ChartArea.Copy



    On Error Resume Next
    'Colle la plage Excel avec liaison à l'emplacement du curseur
    Selection.PasteSpecial Link:=True, DataType:=wdPasteOLEObject, Placement:= _
        wdInLine, DisplayAsIcon:=False
    DoEvents
    XlCl.Close False
    XlAppli.Quit
    Set XlAppli = Nothing
    Set XlCl = Nothing
    Set Xlfl = Nothing
End Sub
dev81 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/04/2007, 15h25   #6
Inactif
 
Avatar de ouskel'n'or
 
Inscription : février 2005
Messages : 12 466
Détails du profil
Informations forums :
Inscription : février 2005
Messages : 12 466
Points : 11 930
Points : 11 930
Excuse, je t'ai laissé tombé
De mémoire :
Code :
1
2
3
4
5
    Xlfl.ChartObjects(1).Select
    ' Select the chart.
    Xlfl.Selection.ChartArea.Select '*******
    ' Copy the chart.
    Xlfl.Selection.Copy
Tu testes avec ou sans la ligne '*******
Pas testé, si ça ne fonctionne pas, je regarderai
A+
ouskel'n'or est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/04/2007, 15h34   #7
Nouveau Membre du Club
 
Inscription : avril 2007
Messages : 116
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 116
Points : 25
Points : 25
Non ca ne marche pas, il n'aime pas la "selection"

revoila 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
Sub InsérerGraphExcel(Path As String)
    Dim XlAppli As Object
    Dim XlCl As Workbook
    Dim Xlfl As Worksheet
    Set XlAppli = CreateObject("Excel.Application") '< L'appli Excel
    Set XlCl = XlAppli.Workbooks.Open(Path) '< le classeur
    Set Xlfl = XlCl.Worksheets("Sheet1") '< la feuille
 
 
    Xlfl.ChartObjects(1).Select
    ' Select the chart.
    Xlfl.Selection.ChartArea.Select
    ' Copy the chart.
    Xlfl.Selection.ChartArea.Copy
 
    'XlAppli.ActiveDocument.Shapes.AddOLEObject FileName:="Path", LinkToFile:=False
    'xxx est une valeur numérique
    'linktofile:=True permet d'ouvrir le fichier EXCEL lorsque vous double-cliquez sur
    'le graphique.
    'left, top, ainsi que height et width définisse la position et la taille du graph
 
 
    On Error Resume Next
    'Colle la plage Excel avec liaison à l'emplacement du curseur
    Selection.PasteSpecial Link:=True, DataType:=wdPasteOLEObject, Placement:= _
        wdInLine, DisplayAsIcon:=False
    DoEvents
    XlCl.Close False
    XlAppli.Quit
    Set XlAppli = Nothing
    Set XlCl = Nothing
    Set Xlfl = Nothing
End Sub
dev81 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/04/2007, 16h40   #8
Nouveau Membre du Club
 
Inscription : avril 2007
Messages : 116
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 116
Points : 25
Points : 25
Toujours un soucis avec la selection du graphe et la copie.Je n'arive pas à faire ca.

Code :
1
2
3
4
5
6
 
    Xlfl.ChartObjects(1).Select
    ' Select the chart.
    Xlfl.Selection.ChartArea.Select
    ' Copy the chart.
    Xlfl.Selection.ChartArea.Copy
[/QUOTE]
dev81 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/04/2007, 17h59   #9
Responsable Visual Basic
 
Avatar de bbil
 
Inscription : juin 2003
Messages : 11 777
Détails du profil
Informations personnelles :
Âge : 45
Localisation : France, Ariège (Midi Pyrénées)

Informations forums :
Inscription : juin 2003
Messages : 11 777
Points : 16 859
Points : 16 859
Envoyer un message via Skype™ à bbil
sur qu'elle ligne l'erreur ... ...
bbil est actuellement connecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/04/2007, 19h14   #10
Inactif
 
Avatar de ouskel'n'or
 
Inscription : février 2005
Messages : 12 466
Détails du profil
Informations forums :
Inscription : février 2005
Messages : 12 466
Points : 11 930
Points : 11 930
Tiens
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Sub CopierUnGrapheExcelDansWord()
Dim XlAppli As Object
Dim XlCl As Workbook
Dim Xlfl As Worksheet
    Set XlAppli = CreateObject("Excel.Application") '< L'appli Excel
    Set XlCl = XlAppli.Workbooks.Open("D:\xls\Fichier.xls") '< le classeur
    Set Xlfl = XlCl.Worksheets("feuil1") '< la feuille
    ' si tu souhaites avoir les noms des différents graphes, tu valides
    'For Each obj In Xlfl.ChartObjects
        'MsgBox obj.Name
    'Next
 
    With Xlfl.ChartObjects("Graphique 1")
        .Copy
    End With
    Selection.Paste
    DoEvents
    'XlCl.Close False
    'XlAppli.Quit
    Set XlAppli = Nothing
    Set XlCl = Nothing
    Set Xlfl = Nothing
End Sub
Testé et tout... Tu as même le nom de fichier en prime
ouskel'n'or est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/04/2007, 08h17   #11
Modérateur
 
Avatar de AlainTech
 
Homme Alain Gerard
Consultant informatique
Inscription : mai 2005
Messages : 3 676
Détails du profil
Informations personnelles :
Nom : Homme Alain Gerard
Âge : 58
Localisation : Belgique

Informations professionnelles :
Activité : Consultant informatique
Secteur : Finance

Informations forums :
Inscription : mai 2005
Messages : 3 676
Points : 7 626
Points : 7 626
Citation:
Envoyé par dev81
Mon VBA ne me reconnait pas la fonction "ChartObjects" pourquoi?
Merci
ChartObjects n'est pas une fonction mais une collection.
__________________
N'oubliez pas de cliquer sur quand vous avez obtenu ou trouvé vous-même la réponse à votre question.
Si vous trouvez seul, pensez à poster votre solution. Elle peut servir à d'autres!
Pensez aussi à voter pour les réponses qui vous ont aidés.
------------
Je dois beaucoup de mes connaissances à mes erreurs!
AlainTech est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/04/2007, 09h31   #12
Nouveau Membre du Club
 
Inscription : avril 2007
Messages : 116
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 116
Points : 25
Points : 25
Merci pour cette aide précieuse.
dev81 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/04/2007, 09h49   #13
Nouveau Membre du Club
 
Inscription : avril 2007
Messages : 116
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 116
Points : 25
Points : 25
Une derniere question.
Je souhaiterai que mon graphe soit inserer dans le texte et pas sur le texte
En fait 2 questions..
Et aussi reduire sa taille de moitié.
C'est possible?Merci
dev81 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 16h11.


 
 
 
 
Partenaires

Hébergement Web