Solved

Adding Excel Chart in Word Template and Editing Progamatically

Posted on 2002-03-05
7
246 Views
Last Modified: 2012-08-13
I created a template in MS Word.  I also inserted an Excel chart object into the document.

What code do I use to access the Excel chart object using vb and edit the chart with new values?

Is the excel chart object the same as graph9.exe?

Thanks
0
Comment
Question by:dmontgom
7 Comments
 
LVL 4

Accepted Solution

by:
WolfgangKoenig earned 100 total points
ID: 6844090
Here is the code to access the com chart object. Therefore
you must link the MS Excel 8.0 Object library to your Word
project file !
aXlsChart is then the com object handle to your chart
object! (the code is for office97, when use office2000 then Excel.Chart.9 and link the 9.0 Object Libary ...)


Sub Makro1()
Dim aWrdShape As InlineShape
Dim aXlsWkb As Workbook
Dim aXlsChart As Chart

Set aWrdShape = Selection.InlineShapes.AddOLEObject(ClassType:="Excel.Chart.8", FileName:="", LinkToFile:=False, DisplayAsIcon:=False)
Set aXlsWkb = aWrdShape.OLEFormat.Object
Set aXlsChart = aXlsWkb.Charts(1)
End Sub


;)
WoK
0
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6844179
Here is the complete code with the source assignment:

Sub Makro1()
Dim aWrdShape As InlineShape
Dim aXlsWkb As Workbook
Dim aXlsChart As Chart
Dim aXlsWs As Excel.Worksheet
Dim aRange As Excel.Range
Set aWrdShape = Selection.InlineShapes.AddOLEObject(ClassType:="Excel.Chart.8", FileName:="", LinkToFile:=False, DisplayAsIcon:=False)
Set aXlsWkb = aWrdShape.OLEFormat.Object
' Get Object Handle
Set aXlsChart = aXlsWkb.Charts(1)
Set aXlsWs = aXlsWkb.Worksheets(1)
' Assign Source
Set aRange = aXlsWs.Range("A1:D7")
Call aXlsChart.SetSourceData(aRange)
End Sub


Hope that solves your problem...
;)
WoK
0
 

Author Comment

by:dmontgom
ID: 6845049
Is the excel chart object using graph9.exe?  

Thanks
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

Author Comment

by:dmontgom
ID: 6845166
Also,

I already have an excel chart object on the word page.  I am not adding a chart programtically and then editing.  What I want to know is with an already existing chart, how do I edit the contents.

Thanks for your help
0
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6846907
Ok, here is the adapted code to change the content
of an existing chart in a word document:

Sub Makro1()
Dim aWrdShape As InlineShape
Dim aXlsWkb As Excel.Workbook
Dim aXlsChart As Excel.Chart
Dim aXlsWs As Excel.Worksheet
Dim aRange As Excel.Range

' Search for an existing chart in word document
For Each aWrdShape In Application.ActiveDocument.InlineShapes
   ' Get the handle to the excel workbook
    Set aXlsWkb = aWrdShape.OLEFormat.Object
   ' Get the handle to the excel worksheet
    Set aXlsWs = aXlsWkb.Worksheets(1)
   ' Get the handle to the excel chart in the worksheet
    Set aXlsChart = aXlsWs.ChartObjects(1)
   
    ' Assign new contents via source method
    Set aRange = aXlsWs.Range("A1:D7")
    Call aXlsChart.SetSourceData(aRange)
Next
End Sub


Beside:
The Range("A1:D7") holds data like this:
       food fuel hotel
jan    12   10   17
feb    17   11   21
march  ...
april
may
june


Hope that is what you need... When you need to modify
the content not programtically then just double click
on the chart and then right click (context menu) and then
choose 'data source' ...

;)
WoK
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6914628
Hi dmontgom, any update on this question?

in an effort to clean up old open questions

your options are:

1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
  --> Post comments for expert of your intention to delete and why
  --> You cannot delete a question with comments, special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below, include the question
QID/link. http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

Please click this Help Desk link for Member Guidelines, Member Agreement and the Question/Answer process: Click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues. http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

------------>  EXPERTS:    Please leave any comments regarding this question here on closing recommendations if this item remains inactive another seven (7) days.

:O)Bruintje
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6974197
Per recommendation, force-accepted by
Netminder
CS Moderator
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Recursion / Iteration in Word 2013 Mail Merge 16 74
Outlook 2010 Archive 3 71
Excel sheet question 12 44
how to re-acticvate Office 2010 6 41
Some time ago I was asked to create a VBA function that would calculate a check digit for an input number, using the following procedure: First, sum up all the individual digits in the number If that sum value has more than one digit, then sum up …
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question