Solved

Adding Excel Chart in Word Template and Editing Progamatically

Posted on 2002-03-05
7
249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
Cancel future meetings from user mailboxes in Office 365 using Remove-CalendarEvents
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

624 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