PDA

View Full Version : Pasting excel charts in Word with Text



panks_r
08-01-2009, 02:19 PM
Hi,

I am writing a program to generate word documents which contain data pulled in from excel along with some charts. I am using PasteSpecial function to paste the charts from excel to word. But image is currently overwriting any text, I might have in the document. I tried using both the wdCollaspeEnd and wdCollapseStart functions but it did not work for me. I have pasted the code snipet below.
With wrdDoc
Dim ch As ChartObject
Set ch = Worksheets("Permanent Workforce Chart").ChartObjects(1)
ch.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
'Custom Text
.Content.InsertAfter "Report 2009"
.Content.InsertParagraphAfter
.Content.InsertAfter strCompName
.Content.InsertParagraphAfter

.Content.Collapse (WdCollapseDirection.wdCollapseEnd)
.Content.PasteSpecial Placement:=WdOLEPlacement.wdInLine, DataType:=WdPasteDataType.wdPasteBitmap

.SaveAs ("<doc name>")
.Close ' close the document
End With
wrdApp.Quit ' close the Word application
Set wrdDoc = Nothing
Set wrdApp = Nothing

Can someone please help me on this?
-Thanks

lucas
08-02-2009, 07:30 AM
One possible solution would be to use bookmarks in the word document to put the chart where you want it to be I guess:

http://www.vbaexpress.com/kb/getarticle.php?kb_id=133