Copy Chart from Excel to Word using VBA

G

Guest

Using VBA, how do I copy an chart from Excel to a Word document using VBA?
I can already copy cells and place them at Word bookmarks.
 
J

Jon Peltier

"The" document is not open, or "a" document is not open. The code should be
looking for any document.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______


Tom said:
When I try the code to Paste the Active Excel Chart at the Cursor in the
Active Word Document I get an error message that indicates that the
command
is not available because the document is not open. However I do have a
Word
Document open
 
T

Tom

Jon,

Here is my code. I have one routine to create the word document and another
to reference the active word doc and copy the charts into it:

Sub CopyCharts()

Dim WDApp As Word.Application
Dim WDDoc As Word.Document

Call CreateWordDocumentFromExcel

Dim i As Integer

' Reference existing instance of Word
Set WDApp = GetObject(, "Word.Application")

' Reference active document
Set WDDoc = WDApp.ActiveDocument (I get the error at this line)

For iCht = 1 To ActiveSheet.ChartObjects.count

With ActiveSheet.ChartObjects(iCht).Chart
' copy chart as a picture
.CopyPicture _
Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture
' Paste chart at cursor position
WDApp.Selection.PasteSpecial Link:=False,
DataType:=wdPasteMetafilePicture, _
Placement:=wdInLine, DisplayAsIcon:=False

End With

Next

' Clean up
Set WDDoc = Nothing
Set WDApp = Nothing

End sub

Sub CreateWordDocumentFromExcel()

Dim oWord As Object
Set oWord = CreateObject("Word.application")
oWord.Visible = True
AppActivate oWord
With oWord.Documents
..Add
End With


'Set oWord = Nothing
End Sub
 
J

Jon Peltier

Is there only one running instance of Word? No hidden orphan instances that
are visible in the Task Manager?

- Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top