Word vba that copies Excel graph into Word doc

T

tomfabtastic

Hi,

Just wondering if anyone has some code that copies a graph from an
excel doument and pastes it into a word doc ? I need a word vba macro
for this, I don't want to paste with link.

When I rty and record the macro I only get :
Selection.PasteAndFormat (wdChartPicture)

Thanks,
Tom
 
H

Helmut Weber

Hi Tom,

Sub Testx()
Dim oExl As Excel.Application
Set oExl = GetObject(, "Excel.application")
oExl.ActiveWorkbook.ActiveSheet.Shapes(1).Copy
Selection.Paste
' ...
End Sub

assumed:
early binding,
http://word.mvps.org/FAQs/InterDev/EarlyvsLateBinding.htm
Excel running,
workbook in question open,
worksheet in question is activesheet,
chart in question is shape(1) of activesheet.

See as well:
http://word.mvps.org/faqs/interdev/ControlXLFromWord.htm




--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
T

tomfabtastic

Hi Tom,

Sub Testx()
Dim oExl As Excel.Application
Set oExl = GetObject(, "Excel.application")
oExl.ActiveWorkbook.ActiveSheet.Shapes(1).Copy
Selection.Paste
' ...
End Sub

assumed:
early binding,http://word.mvps.org/FAQs/InterDev/EarlyvsLateBinding.htm
Excel running,
workbook in question open,
worksheet in question is activesheet,
chart in question is shape(1) of activesheet.

See as well:http://word.mvps.org/faqs/interdev/ControlXLFromWord.htm

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP

Thanks Helmut,

That works - but when the graph is pasted into word it is pasted with
an odd format. I would like the graph to show as it would if I went
into excel and copied the graph, and then Pasted Special into excel
(enhanced metafile - no ink).

Do you know how to do that ?
 
H

Helmut Weber

Hi Tom,

the shape I paste looks exactly like it looks in Excel.

You may try Selection.PasteSpecial plus the various
datatype-constants, like:

Selection.PasteSpecial DataType:=wdPasteEnhancedMetafile
or
Selection.PasteSpecial DataType:=wdPasteMetafilePicture

However, here and now, there is no difference.
 

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