Microsoft 365 Copier graphes excel dans word

lestatber

XLDnaute Nouveau
Bonjour,


J'ai une macro qui copie tous les graphiques dans un document word, elle fonctionne dans mon fichier de test mais dans mon fichier de destination qui a beaucoup de macro et de données (20000 lignes), la macro plante.


Savez-vous comment modifier ce code pour copier des graphiques nommés et non tous les graphiques disponibles afin d'optimiser le code et éviter le plantage de la macro.

Voici mon code :


Sub WordCopy()
'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
' WrdApp.ScreenUpdating = False

'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


1649668211013.png

Merci d'avance
 

Pièces jointes

  • test.xlsm
    28.9 KB · Affichages: 4

Discussions similaires

Statistiques des forums

Discussions
312 080
Messages
2 085 149
Membres
102 794
dernier inscrit
espinata