Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Insert Excel Chart in Word
Message
From
19/07/2011 11:53:24
Victor Chignes
Inteliventas
Peru
 
 
To
19/07/2011 11:15:30
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
01518504
Message ID:
01518518
Views:
51
Frank:
Put a suspend after the ObjXLsheet.ChartObjects(1).copy and see if you can open word and paste normally. If so save what you did in a macro and reproduce it in code.

>Sorry, I copied the code out of the oleaut1.scx sample form from the Solutions that came with VFP and the comments that are there, that I left out are:
>
>**** Because the excel objects were already RELEASEd
>**** the graph must be pasted w/o a link.
>**** It is pasted as a PICTURE instead of a GRAPH
>**** To paste as a link, you would use this command
>**** objWDdoc.editpaste
>**** AND you would have to make sure the Excel Objects
>**** were not RELEASEd and that Excel was still running
>
>So I don't think that is it.
>
>The rest of the code in the sample uses Word.Basic, but I don't think I could use that to open a template and replace bookmarks I am trying to adapt that code to using a Word.Application. Here's that code:
>
>
#DEFINE APPSHOW_WORDUS_LOC			"appshow"
>#DEFINE FILENEW_WORDUS_LOC			"filenewdefault"
>#DEFINE INSERT_WORDUS_LOC			'insert("Here is your graph!")'
>#DEFINE EDITPASTESPECIAL_WORDUS_LOC	"editpastespecial(,,,,'PICT')"
>
>objWDdoc=crea("word.basic")
>objwddoc.&APPSHOW_WORDUS	&&added 8/17 for Word 7.0 support
>objwddoc.&FILENEW_WORDUS
>objwddoc.&INSERT_WORDUS
>objwddoc.&EDITPASTESPECIAL_WORDUS
>
>>Maybe if you don't close excel before the paste (just a wild guess)
>>>Hi,
>>>
>>>I am trying to create a chart in Excel and then place it in a Word document.
>>>
>>>I have created the chart and put a bookmark in the document, but the image of the chart is not pasted where the bookmark is. Here's my code:
>>>
>>>
loWord = CREATEOBJECT("Word.Application")
>>>SCAN 
>>>	loWord.Documents.Add("GroupPlan.dot")
>>>	m.loDoc = m.loWord.ActiveDocument
>>>	
>>>	objXLsheet=CreateObject("Excel.Sheet")
>>>
>>>	* Excel 97 Automation change
>>>	* CreateObject() returns Object instead of Sheet1
>>>	IF UPPER(objXLsheet.Name)= "OBJECT"
>>>		lHasExcel97 = .T.
>>>		objXLsheet = objXLsheet.Sheets[1]
>>>	ELSE
>>>		lHasExcel97 = .F.
>>>	ENDIF
>>>
>>>	m.lnRowCount = 0
>>>	SCAN 	
>>>		m.lnRowCount = m.lnRowCount + 1 
>>>		objXLsheet.Cells[m.lnRowCount,1].Value = c_TurnaroundChart.Y
>>>		objXLsheet.Cells[m.lnRowCount,2].Value = c_TurnaroundChart.M
>>>		objXLsheet.Cells[m.lnRowCount,3].Value = c_TurnaroundChart.TotalReceived
>>>		objXLsheet.Cells[m.lnRowCount,4].Value = c_TurnaroundChart.AvgTurnaround
>>>	ENDSCAN
>>>	
>>>	objChart1 = objXLsheet.ChartObjects.Add(100, 100, 200, 200)
>>>
>>>	objxlsheet.chartobjects(1).chart.;
>>>		chartwizard(objxlsheet.range(objxlsheet.cells(1,1),objxlsheet.cells(m.lnRowCount,4)),;
>>>		-4100,4,1,0,1,1,"","","","")
>>>	*!*	objXLsheet.application.visible=.T.
>>>
>>>	ObjXLsheet.ChartObjects(1).select
>>>	ObjXLsheet.ChartObjects(1).copy
>>>
>>>	IF !m.lHasExcel97
>>>		objXLsheet.application.quit
>>>	ENDIF
>>>	release objXLsheet
>>>
>>> 	IF m.loDoc.Bookmarks.EXISTS("TurnAroundChart")
>>>		m.loDoc.Bookmarks("TurnAroundChart").SELECT
>>>		m.loDoc.APPLICATION.Selection.Paste()	&&.PasteSpecial(,,,,'PICT')
>>>	ENDIF
>>>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform