From: hans on
Hi,

I'm writing an asp application in wich I dynamically create an
Excel-graph.
Now I'd like to copy that graph, open word and paste it on the
apropiate bookmark.

I use the following lines of code to copy the graph:

oExcelSht.ChartObjects("Graph 1").Activate
ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Copy

Then I open a word document to paste that graph into it, but I don't
find the correct syntax to do it.
I created a macro in word to see the code it produced, but don't manage
to transform it into correct asp-code. Can someone help me please?

oWordDoc.Bookmarks("product").Range.PasteSpecial Link = False, DataType
= wdPasteBitmap, Placement = wdInLine, DisplayAsIcon = False

Thanks

From: Cindy M -WordMVP- on
Hi Hans,

How is the code you post not working for you through an asp interface?

Are you able to save this Excel workbook with the graph to disk?

If you are, then I recommend NOT going over the clipboard
(Insert/Object/From File), or replicating the result you'd get if you
went over PasteSpecial with a link, then break the link (which should
give you a graphic in the document).

Or create the graph directly in the Word document, then unlink the OLE
field code to turn it into a graphic.

Does any of these sound like a possible approach?

> I'm writing an asp application in wich I dynamically create an
> Excel-graph.
> Now I'd like to copy that graph, open word and paste it on the
> apropiate bookmark.
>
> I use the following lines of code to copy the graph:
>
> oExcelSht.ChartObjects("Graph 1").Activate
> ActiveChart.ChartArea.Select
> ActiveChart.ChartArea.Copy
>
> Then I open a word document to paste that graph into it, but I don't
> find the correct syntax to do it.
> I created a macro in word to see the code it produced, but don't manage
> to transform it into correct asp-code. Can someone help me please?
>
> oWordDoc.Bookmarks("product").Range.PasteSpecial Link = False, DataType
> = wdPasteBitmap, Placement = wdInLine, DisplayAsIcon = False
>

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)

From: hans on
Hi Cindy,

This could be a solution, but the problem is that I have to create
hundreds of graphs that will be dynamically altered, so I should save
the excel-file each time, insert the object in word; open excel again
to change the graph, close it again end so on.

Instead I created the following code to do the job, but unfortunately I
get an error (see below):

oExcelSht.ChartObjects("Graph 1").Activate
oExcelApp.ActiveChart.ChartArea.Select
oExcelApp.ActiveChart.ChartArea.Copy

'Create an instance of Word Application
set oWordApp = Server.CreateObject("Word.Application")

'Make wordApp visible
oWordApp.visible = true
oWordApp.DisplayAlerts = false

'New document (based on sWordTemplateFile)
set oWordDoc = oWordApp.Documents.Add(sWordTemplateFile)

'Paste chart
oWordApp.selection.paste

'Save document
oWordApp.ActiveDocument.SaveAs sWordTargetFile

'Quit Word
oWordDoc.close
oWordApp.Quit
set oWordDoc = Nothing
set oWordApp = Nothing

The error I get is:
Runtime error 4605: This method or property is not valid because the
Clipboard is empty or not valid.

Do you know why I get this error?

From: hans on
Cindy,

I found what caused the error. For some reasen word was opened by a
different user as the one that opened excel. Obviously the clipboard is
empty in that case!!!
Thanks for your effort anyway!!!

Hans