Bonjour,
Merci pour vos réponses à ma dernières question,
Maintenant, j'ai un fichier excel et j'exporte (j'essaie) plusieurs graphiques vers un docword, pour cela j'utilise ce code inspiré d'une page msn.vba...:
Ainsi je lance cette macro avec un bouton de commande, et je fais de même pour chaque graphique, ce qui est très long...
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 Sub Bouton1_Cliquer_exportun() 'Name of an existing Word document, and the name the chart will have when exported. Const stWordDocument As String = "Rapport de graphique.docx" Const stChartName As String = "ChartReport1.gif" 'Word objects. Dim wdApp As Word.Application Dim wdDoc As Word.Document Dim wdbmRange As Word.Range 'Excel objects. Dim wbBook As Workbook Dim wsSheet As Worksheet Dim ChartObj As ChartObject 'Initialize the Excel objets. Set wbBook = ThisWorkbook Set wsSheet = wbBook.Worksheets("Résumé nuit") Set ChartObj = wsSheet.ChartObjects("Graphique 1") 'Turn off screen updating. Application.ScreenUpdating = False 'Export the chart to the current directory, using the specified name, and save the chart as a .gif ChartObj.Chart.Export _ Filename:=wbBook.Path & "\" & stChartName, _ FilterName:="GIF" 'Initialize the Word objets to the existing Word document and bookmark. Set wdApp = New Word.Application Set wdDoc = wdApp.Documents.Open(wbBook.Path & "\" & stWordDocument) Set wdbmRange = wdDoc.Bookmarks("ChartReport1").Range 'If there is already an inline shape, that means the macro has been run before - clean up any artifacts. On Error Resume Next With wdDoc.InlineShapes(1) .Select .Delete End With On Error GoTo 0 'Add the .gif file to the document at the bookmarked location, 'and ensure that it is saved inside the Word doc. With wdbmRange .Select .InlineShapes.AddPicture _ Filename:=wbBook.Path & "\" & stChartName, _ LinkToFile:=False, _ savewithdocument:=True End With 'Save and close the Word document. With wdDoc .Save .Close End With 'Quit Word. wdApp.Quit 'Clear the variables. Set wdbmRange = Nothing Set wdDoc = Nothing Set wdApp = Nothing 'Delete the temporary .gif file. On Error Resume Next Kill wbBook.Path & "\" & stChartName On Error GoTo 0 MsgBox "Graphique exporté avec succès " & stWordDocument End Sub
Est-ce qu'il est possbile Soit d'affecter deux macros à un bouton ? ou Soit de changer: Const stChartName As String = "ChartReport1.gif" en 2 et les dim As, Set =, qui suivent aussi ?
Merci si vous pouvez me répondre.
Cordialement
ps: et dans ce code je ne parviens à changer le chemin du document word, si vous avez une idée, vous êtes le bienvenu![]()
Partager