Results 1 to 8 of 8

Thread: Trying to add a chart to a powerpoint presentation in vb.net???

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    7

    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]

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Trying to add a chart to a powerpoint presentation in vb.net???

    Here's some sample code to get you started.
    VB Code:
    1. Option Explicit
    2.  
    3. Sub BuildPPChart()
    4. Dim pptApp As PowerPoint.Application
    5. Dim pptPres As PowerPoint.Presentation
    6. Dim pptSlide As PowerPoint.Slide
    7. Dim pptGraphHolder As PowerPoint.Shape
    8. Dim gphChart As Graph.Chart
    9. Dim x As Long, y As Long
    10.  
    11.     'Setup object variables
    12.     'new PP Application
    13.     Set pptApp = New PowerPoint.Application
    14.     'new PP Presentation
    15.     Set pptPres = pptApp.Presentations.Add
    16.     'new PP Slide
    17.     Set pptSlide = pptPres.Slides.Add(1, ppLayoutBlank)
    18.     'New Graph Shape
    19.     Set pptGraphHolder = pptSlide.Shapes.AddOLEObject(Left:=120, Top:=110, Width:=480, Height:=320, ClassName:="MSGraph.Chart", Link:=msoFalse)
    20.    
    21.     'Take control of the graph
    22.     Set gphChart = pptGraphHolder.OLEFormat.Object
    23.    
    24.     With gphChart
    25.         'Change the chart type
    26.         .ChartType = xlLine
    27.        
    28.         With .Application.DataSheet
    29.             'Clear the default data
    30.             .Range("00", "Z100").Clear
    31.            
    32.             'Add heading
    33.             .Range("01").Value = "Tom"
    34.             .Range("02").Value = "Dick"
    35.             .Range("03").Value = "Harry"
    36.            
    37.             .Range("A0").Value = "2004"
    38.             .Range("B0").Value = "2005"
    39.             .Range("C0").Value = "2006"
    40.                        
    41.             'Populate sample data
    42.             For x = 2 To 4
    43.                 For y = 2 To 4
    44.                 .Cells(x, y).Value = CLng(Rnd() * 100)
    45.                 Next
    46.             Next
    47.         End With
    48.     End With
    49.    
    50.     'show the reslut
    51.     pptApp.Visible = msoTrue
    52.    
    53.     'Clear variables
    54.     Set gphChart = Nothing
    55.     Set pptGraphHolder = Nothing
    56.     Set pptSlide = Nothing
    57.     Set pptPres = Nothing
    58.     Set pptApp = Nothing
    59. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    7

    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,

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    7

    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...

  5. #5
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    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

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    7

    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

  7. #7
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    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

  8. #8

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    7

    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
  •  



Click Here to Expand Forum to Full Width