Mon VBA ne me reconnait pas la fonction "ChartObjects" pourquoi?
Merci
Version imprimable
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 :mouarf:Citation:
Envoyé par dev81
Tu fais ça ?
A+
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
Comment on utilise les "ChartObjects"?
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
Excuse, je t'ai laissé tombé
De mémoire :
Tu testes avec ou sans la ligne '*******Code:
1
2
3
4
5 Xlfl.ChartObjects(1).Select ' Select the chart. Xlfl.Selection.ChartArea.Select '******* ' Copy the chart. Xlfl.Selection.Copy
Pas testé, si ça ne fonctionne pas, je regarderai
A+
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
Toujours un soucis avec la selection du graphe et la copie.Je n'arive pas à faire ca.
[/QUOTE]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
sur qu'elle ligne l'erreur ... ...
Tiens
Testé et tout... Tu as même le nom de fichier en primeCode:
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
ChartObjects n'est pas une fonction mais une collection.Citation:
Envoyé par dev81
Merci pour cette aide précieuse.:P :) :P :)
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