Excel VBA - Easy way to paste chart to word document ?

J

JtR

Sorry i am neewbie with excel macros


Whats is the easyest way to paste chart to word document ? And how t
open word document from excel ?

I all ready have bookmarks in word document and they works fine, but
my macro (excel) copy and other macro in word paste chart how to manag
then starts in order. Mayby i am making something wrong way i think :
 
J

JtR

Thanks for reply

I got that to work last night :) My biggest problem was missin
reference to word :)

But now i have new problem i am pasting charts to word in picture mode
but how do i know that picture name in word of chart. Cos i have t
delete that picture next time when i am running excel macro again
Otherwise paste put other one picture that's looks kinda stupid ;
 
G

Guest

For your word referencing problem, try the following code

'Define a Word Document Object
Dim WordDoc as word.document

'Set WordDoc as your word document template
Set WordDoc = WordApp.Documents.Open _
(FileName:=LetTempLoc, ReadOnly:=True)

With these codes everytime when you refer to "WordDoc" you are referring to the word document

You could paste the chart as a link. Though I am not sure about the codes. You can record it to see that it looks like (from Word). A word of cautions though: links from Word to Excel will take long time to load. I have once linked 10 charts from Excel to Word and it took 15 minutes to load.

Instead I create a macro that acts like a mail merge and place charts, delete paragraphs, put in names and other information required on the document. Every time when I need to update, I just rerun the macro to recreate the whole word document. It takes seconds. I have produced hundreds of letters with attached charts that way.
 
J

JtR

Thanks again for information

I have working macro now what pastes chart's to document.

But that document has multiple editors (users, macros), so i cant d
allways new document cos there is text what change by users. Any ide
to work with this ?


Example what type document i have:

text (users update text)

chartpicture (my macro puts this)
text (users update text)
 
G

Guest

Is there a reason why you need a macro to do this? I normally let the stake holders make the changes before using the macro to create the final mass production. If they have any additional changes, I would let them change the word document template and inform them not to change anything that could affect the workings of my macro (I made all the flags in blue text). I then reran the macros with the revised template. That also works on the changes to the values of the tables since the macro is only a tools that copy and paste from one medium to another.
 
J

Jon Peltier

If you paste the chart at a bookmark in Word, you can go back to the
bookmark, and delete the chart:

Paste at the bookmark:

' Go to bookmark "chart1"
WDApp.Selection.GoTo What:=wdGoToBookmark, Name:="chart1"

' Paste chart at cursor position
WDApp.Selection.PasteSpecial Link:=False, _
DataType:=wdPasteMetafilePicture, _
Placement:=wdInLine, DisplayAsIcon:=False

Delete the chart at the bookmark:

' Go to bookmark "chart1"
WDApp.Selection.GoTo What:=wdGoToBookmark, Name:="chart1"

' Extend selection one character right to select the shape
WDApp.Selection.MoveRight Unit:=wdCharacter, Count:=1, _
Extend:=wdExtend
WDApp.Selection.Delete

I wish I understood better how it worked, but Word's object model always
gives me a headache.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______
 
J

JtR

Thanks for reply's

Jon Peltier that delete think work fine thanks. I manage to finish m
little macro :
 

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