Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub Copy_Paste_Report_1_Graph_to_new_word_document()
- '
- 'Copy/Paste An Excel Chart Into a New Word Document
- '(VBE > Tools > References > Microsoft Word 12.0 Object Library)
- 'Excel Objects
- Dim ChartObj As ChartObject
- 'Word Objects
- Dim WordApp As Word.Application
- Dim myDoc As Word.Document
- Dim WordTable As Word.Table
- 'Optimize Code
- Application.ScreenUpdating = False
- Application.EnableEvents = False
- 'Copy Chart from Excel
- Set ChartObj = Worksheets("External Dashboard").ChartObjects("Chart 1")
- 'Create an Instance of MS Word
- On Error Resume Next
- 'Is MS Word already opened?
- Set WordApp = GetObject(class:="Word.Application")
- 'Clear the error between errors
- Err.Clear
- 'If MS Word is not already open then open MS Word
- If WordApp Is Nothing Then Set WordApp = CreateObject(class:="Word.Application")
- 'Handle if the Word Application is not found
- If Err.Number = 429 Then
- MsgBox "Microsoft Word could not be found, aborting."
- GoTo EndRoutine
- End If
- On Error GoTo 0
- 'Make MS Word Visible and Active
- WordApp.Visible = True
- WordApp.Activate
- 'Create a New Document
- Set myDoc = WordApp.Documents.Add
- 'Copy Excel Chart
- ChartObj.Copy
- 'Paste Chart into MS Word
- myDoc.Paragraphs(1).Range.PasteSpecial Link:=False _
- EndRoutine:
- 'Optimize Code
- Application.ScreenUpdating = True
- Application.EnableEvents = True
- 'Clear The Clipboard
- Application.CutCopyMode = False
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement