Microsoft 365 Export Graph au format image dans un document word

lestatber

XLDnaute Nouveau
Bonjour,



J'essaie d'exporter une page contenant plusieurs graphiques dans un document Word (format image) via un script VBA.

Mon script pour l'export d'un graph fonctionne mais pas celui pour plusieurs graph

j'ai une erreur dans la déclaration ou l'importation de la library car le système renvoie l'erreur suivante

1649607523741.png

Je pense que c'est du la déclaration suivante :

Dim WrdApp As Word.Application

pouvez Vous voir ce qui ne va pas, j'ai ajouté la library Microsoft Word 16.0 Object library mais cela ne résout pas le problème


Merci,

Matthieu
 

Pièces jointes

  • 1649607833243.png
    1649607833243.png
    71.1 KB · Affichages: 26
  • 1649607837061.png
    1649607837061.png
    71.1 KB · Affichages: 25
  • test.xlsm
    29.9 KB · Affichages: 1

lestatber

XLDnaute Nouveau
j'ai trouvé,

le bon code est le suivant

Sub Test()

'Declare Word Variables
'Dim WrdApp As Word.Application
Dim WrdApp As Object
Dim WrdDoc As Object
Dim SecCnt As Integer


'Declare Excel Variables
Dim ChrtObj As ChartObject
Dim Rng As Range

'Create a new instance of Word
Set WrdApp = CreateObject("Word.Application")
WrdApp.Visible = True
WrdApp.Activate

'Create a new word document
Set WrdDoc = WrdApp.Documents.Add

'Loop through the charts on the active sheet
For Each ChrtObj In ActiveSheet.ChartObjects

'Copy the chart
ChrtObj.Chart.ChartArea.Copy

'Paste the Chart in the Word Document
With WrdApp.Selection
.PasteSpecial Link:=True, DataType:=wdPasteOLEObject, Placement:=wdInLine
End With

'Count the pages in the Word Document
SecCnt = WrdApp.ActiveDocument.Sections.Count

'Add a new page to the document.
WrdApp.ActiveDocument.Sections.Add

'Go to the newly created page.
WrdApp.Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext

Next ChrtObj

End Sub
 

Discussions similaires

Statistiques des forums

Discussions
312 109
Messages
2 085 384
Membres
102 878
dernier inscrit
asmaa