|
-
Mar 28th, 2006, 06:43 PM
#1
Thread Starter
New Member
Trying to add a chart to a powerpoint presentation in vb.net???
Howdy All,
I'm haveing a heck of a time trying (in VB.net) to add a chart to a powerpoint presentation that I'm build via code...
I'm looking at using the MSChart object, but I might consider the Office Web Components is neccessary.
I have no clue as to where even to begin... I can add a slide to the presentation no problem, but once I do that what to I do???
I've add a OLEObject/MSChart" to the page, but can't seem to modify beyond the default chart type and chart data... I need to change the type and add specific data to the chart...
Here's where I gone so for, Which may be total wrong, please tell me!!!
Dim PP As PowerPoint.Application
Dim Pres As PowerPoint.Presentation
Pres.Slides.Item("Slide2").Select()
Pres.Slides.Item("Slide2").Copy()
Pres.Slides.Item(Pres.Slides.Count).Select()
PP.ActiveWindow.View.Paste()
intSlideIndex = Pres.Slides.Count
Pres.Slides.Item(intSlideIndex).Select()
PP.ActiveWindow.Selection.SlideRange.Shapes.AddOLE Object(50, 50, 500, 300, "MSGraph.Chart", , Core.MsoTriState.msoFalse, , , , Core.MsoTriState.msoCTrue).Select()
NOW WHAT?????
Thanks in advance,
Kevin Orcutt
Software Engineer
SAEC/kinetic vision
[email protected]
-
Mar 29th, 2006, 03:47 PM
#2
Re: Trying to add a chart to a powerpoint presentation in vb.net???
Here's some sample code to get you started.
VB Code:
Option Explicit
Sub BuildPPChart()
Dim pptApp As PowerPoint.Application
Dim pptPres As PowerPoint.Presentation
Dim pptSlide As PowerPoint.Slide
Dim pptGraphHolder As PowerPoint.Shape
Dim gphChart As Graph.Chart
Dim x As Long, y As Long
'Setup object variables
'new PP Application
Set pptApp = New PowerPoint.Application
'new PP Presentation
Set pptPres = pptApp.Presentations.Add
'new PP Slide
Set pptSlide = pptPres.Slides.Add(1, ppLayoutBlank)
'New Graph Shape
Set pptGraphHolder = pptSlide.Shapes.AddOLEObject(Left:=120, Top:=110, Width:=480, Height:=320, ClassName:="MSGraph.Chart", Link:=msoFalse)
'Take control of the graph
Set gphChart = pptGraphHolder.OLEFormat.Object
With gphChart
'Change the chart type
.ChartType = xlLine
With .Application.DataSheet
'Clear the default data
.Range("00", "Z100").Clear
'Add heading
.Range("01").Value = "Tom"
.Range("02").Value = "Dick"
.Range("03").Value = "Harry"
.Range("A0").Value = "2004"
.Range("B0").Value = "2005"
.Range("C0").Value = "2006"
'Populate sample data
For x = 2 To 4
For y = 2 To 4
.Cells(x, y).Value = CLng(Rnd() * 100)
Next
Next
End With
End With
'show the reslut
pptApp.Visible = msoTrue
'Clear variables
Set gphChart = Nothing
Set pptGraphHolder = Nothing
Set pptSlide = Nothing
Set pptPres = Nothing
Set pptApp = Nothing
End Sub
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Mar 29th, 2006, 04:48 PM
#3
Thread Starter
New Member
Re: Trying to add a chart to a powerpoint presentation in vb.net???
OK, I seem to understand much of what you supplied. However, In vb.net that editor has a problem with the line
Dim gphChart As Graph.Chart
It underlines the Grapg.Chart statement. Saying "Type 'Graph.Chart' is not defined."
OK so what am I missing??? What else do I need to reference to or Imports???
Thanks,
-
Mar 29th, 2006, 04:50 PM
#4
Thread Starter
New Member
Re: Trying to add a chart to a powerpoint presentation in vb.net???
Follow-Up
I am referncing the "MSChart20Lib" com library...
Should I be using something else???
Thanks again...
-
Mar 29th, 2006, 04:54 PM
#5
Re: Trying to add a chart to a powerpoint presentation in vb.net???
You need GRAPH.EXE
The library will be named "Microsoft Graph xx.x Object Library".
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Mar 29th, 2006, 05:07 PM
#6
Thread Starter
New Member
Re: Trying to add a chart to a powerpoint presentation in vb.net???
OK,
Now I've gotten that to work. I've come across ONE Major problem...
When the user "double-clicks" the chart to edit it, it reverts back to the original style and data entries!!!!!
OK, so what did I do wrong????
Thanks
-
Mar 29th, 2006, 05:10 PM
#7
Re: Trying to add a chart to a powerpoint presentation in vb.net???
You copied my code exactly? I ask this because when I edit the graph it retains the data that I passed to it through the code.
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Mar 30th, 2006, 02:38 PM
#8
Thread Starter
New Member
Re: Trying to add a chart to a powerpoint presentation in vb.net???
OK,
I've been redirected on this one... See my new post for the follow-on... Basically I now need to fire off an Excel app to produce the chart, and I'm having some issues there...
See you on the flip side..
Kevin Orcutt
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|