在excel中编辑word文件,插入图表

在excel中编辑word文件,插入图表

Sub test()
Dim wApp, currentpath, name, savepath
Dim i As Integer

name = Cells(1, "c").Text & ".docx"  'name sample report
currentpath = ThisWorkbook.Path & "\"                     'define current path
savepath = ThisWorkbook.Path & "\sample\"                 'save path
FileCopy currentpath & "template.docx", savepath & name   'copy file, save and rename


ThisWorkbook.Worksheets("result").ChartObjects(1).Activate
ActiveChart.ChartArea.Copy
Set wApp = CreateObject("word.application")

With wApp
  .Visible = False
  .Documents.Open savepath & name                          'open sample report
  
.activedocument.Bookmarks("CH1").Range.Select
.Selection.Paste
  
  .Documents.Save
  .Quit

End With
Set wApp = Nothing

End Sub

Sub test()
Dim wApp, currentpath, name, savepath
Dim i As Integer

name = Cells(1, "c").Text & ".docx"  'name sample report
currentpath = ThisWorkbook.Path & "\"                     'define current path
savepath = ThisWorkbook.Path & "\sample\"                 'save path
FileCopy currentpath & "template.docx", savepath & name   'copy file, save and rename



Set wApp = CreateObject("word.application")

With wApp
  .Visible = False
  .Documents.Open savepath & name                          'open sample report
  
 ThisWorkbook.Worksheets("result").ChartObjects(1).Activate
ActiveChart.ChartArea.Copy
.activedocument.Bookmarks("CH1").Range.Select
.Selection.Paste
  
  .Documents.Save
  .Quit

End With
Set wApp = Nothing

End Sub

你可能感兴趣的:(学习Excel)