Excel VBA Macro: Create Word Document & Copy Paste Chart/Graph/Diagram (from Excel)

Excel VBA Macro: Create Word Document & Copy Paste Chart/Graph/Diagram (from Excel).
Code:
Sub add_chart_2_word()
Dim objWord
Dim objDoc
Dim i As Integer
Dim j As Integer
Dim ws As Worksheet
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add
Set ws = ThisWorkbook.Sheets("Sheet1")
With objDoc
.Styles.Add ("Main Title")
.Styles.Add ("Sub Title")
With .Styles("Main Title").Font
.Name = "Calibri"
.Size = 30
.Bold = True
.Color = RGB(26, 134, 31)
End With
With .Styles("Sub Title").Font
.Name = "Arial"
.Size = 15
.Bold = False
.Color = RGB(0, 0, 0)
End With
End With
With objWord
.Visible = True
.Activate
With .Selection
.Style = objDoc.Styles("Main Title")
.typetext ("Country Report")
.typeparagraph
.Style = objDoc.Styles("Sub Title")
.typetext (ws.Cells(8, 1).Text)
.typeparagraph
ws.ChartObjects("Chart 1").Chart.CopyPicture
.Paste
.typeparagraph
.typetext (ws.Cells(9, 1).Text)
.typeparagraph
ws.ChartObjects("Chart 2").Chart.CopyPicture
.Paste
.typeparagraph
End With
End With
End Sub
#ExcelVBA #ExcelMacro

Пікірлер: 3

  • @nikolamn580
    @nikolamn580 Жыл бұрын

    Thank you for this amazing tutorial. What about if I want to save the word file as PDF from the macro.

  • @lavitads9308
    @lavitads930813 күн бұрын

    @greggowaffles How to replace a placeholder in a word doc with chart from excel sheet

  • @coreyterry900
    @coreyterry900 Жыл бұрын

    Hi, So I need to add pie charts like this in a word document. Each word document is for a different person so I will be doing a mail merge but so the data in the pie chart will be different based on the person. Is that possible?