Bonsoir,

J'essaye d'exporter des graph que j'ai sur excel vers un rapports en word, pour cela j'essaye de creer une macro sur mon fichier excel oú j'ai mes graph, voila mon code que j´ai repris sur internet:

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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Sub Exportera_Diagram_Word()
Dim wbBook As Workbook
Dim wsSheet As Worksheet
Dim ctChart As ChartObject
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim BMRange As Word.Range
Dim oShape As Word.InlineShape
 
Set wbBook = ThisWorkbook
Set wsSheet = wbBook.Worksheets("Dispo")
 
With wsSheet
Set ctChart = .ChartObjects("Graph 2")
End With
 
Application.ScreenUpdating = False
 
ctChart.Chart.Export _
Filename:=ThisWorkbook.Path & "\Graph2.jpg", FilterName:="jpg"
 
Set wdApp = CreateObject("Word.Application")
 
Set wdDoc = wdApp.Documents.Open(ThisWorkbook.Path & "\RM__PE_X_XXXXX - MMMM AAAA.docx")
 
'With ActiveDocument.InlineShapes(1)
'.Select
'.Delete
'End With
 
Set BMRange = ActiveDocument.Bookmarks("Graph2").Range
 
With BMRange
.Select
.InlineShapes.AddPicture Filename:= _
ThisWorkbook.Path & "\Graph2.jpg", _
LinkToFile:=False, _
SaveWithDocument:=True
End With
 
With wdApp.ActiveDocument
.Save
 
End With
 
wdApp.Quit
 
Set wdDoc = Nothing
Set wdApp = Nothing
wdoc.Close
wdApp.Quit
 
 
With Application
.CutCopyMode = False
.ScreenUpdating = True
End With
 
Kill ThisWorkbook.Path & "\Graph2.jpg"
 
MsgBox "ReportChart created and copied succesfully to Dennis.doc", vbInformation
 
End Sub

J´ai 2 erreurs qui m’apparaisse:

La première dans la ligne
Code : Sélectionner tout - Visualiser dans une fenêtre à part
With ActiveDocument.InlineShapes(1)
que j'ai dut mettre en commentaire pour que ça passe.

La 2º c'est une erreur OLE
Code : Sélectionner tout - Visualiser dans une fenêtre à part
Set wdDoc = wdApp.Documents.Open(ThisWorkbook.Path & "\RM__PE_X_XXXXX - MMMM AAAA.docx")
Cette erreur m’apparais seulement si je lance la macro plus que une fois de suite. Ça marche au premier fois mais après ça donne erreur.

Quelqu’un peut donner un coup de pouce svp?