Solved

Adding Excel Chart in Word Template and Editing Progamatically

Posted on 2002-03-05
7
244 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Problem: You created a new custom form in Outlook for your contacts (added fields, deleted fields, changed the layout of fields, whatever) and made it the default form for contacts. The good news is that all new contacts will utilize the new form. T…
In case Office 2010 has not been deployed in your environment, this article may be quite useful. In our office, we wanted a way to deploy Microsoft Office Professional Plus 2010 through an automated batch file via logon script. This article is docum…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
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: …

744 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now