?
Solved

Automate powerpoint - create multiple presentations based on data from a database using Visual Basic .NET

Posted on 2004-10-21
1
Medium Priority
?
356 Views
Last Modified: 2008-02-01
Hi!

I'm working on a solution that will create multiple PPT-presentations, each presentation about 15-25 slides and on each slide about 5-15 shapes (graphs and tables). Every graph/table will be updated with data from tab-separated textfiles.

After about 40-50 created reports, PowerPoint crashes and generates an error message saying something like "The RPC-server is unavailable.".

My question is: how do I best declare the objects and should this be in or outside the loop with the reports? Today the code looks something like:

Public Class CreatePPTReports
    Dim oApp As Microsoft.Office.Interop.Powerpoint.Application
    Dim oPres As Microsoft.Office.Interop.PowerPoint.Presentation

    Public Sub CreatePPT()

        'reports is the array containing the reports to be created
        For Each itm As String In Reports
            Dim oPreses As Microsoft.Office.Interop.PowerPoint.Presentations
            Dim oPres As Microsoft.Office.Interop.powerPoint.Presentation
            Dim oSlides As Microsoft.Office.Interop.PowerPoint.Slides
            Dim oSlide As Microsoft.Office.Interop.PowerPoint.Slide
            Dim oShape As Microsoft.Office.Interop.PowerPoint.Shape
            Dim oShapes As Microsoft.Office.Interop.PowerPoint.Shapes
            Dim oTextFrame As Microsoft.Office.Interop.PowerPoint.TextFrame
            Dim oTextRange As Microsoft.Office.Interop.PowerPoint.TextRange

            pb.Value += 1
            pb1.Minimum = 0
            pb1.Value = 0
            pb1.Step = 1

            Try
                oApp = New Microsoft.Office.Interop.PowerPoint.Application

                oPreses = oApp.Presentations
                oPres = oPreses.Open(itm & ".ppt", , , False)
                oSlides = oPres.Slides
            Catch ex As Exception
              'error goes here
            End Try

           'loop through slides goes here
            For Each oSlide In oSlides
                oShapes = oSlide.Shapes
               
                'resultarray is fetched
                Dim PageArr() = RetrieveResult(itm & ".txt", Delimiter & oSlide.SlideIndex, "_")
                Dim AIFound As Boolean = False

               'shapeloop goes here...
                For Each oShape In oShapes
                    If InStr(oShape.Name, " ") = 0 Then
                        Dim ShapeArr() = RetrieveShapeResult(PageArr, oShape.Name)

                                    'graph is updated here
                                    oOLEFORMAT = oShape.OLEFormat
                                    oChart = oOLEFORMAT.Object
                                    For Each aItm As String In ShapeArr
                                        Dim tmparr = Split(aItm, Delimiter)
                                        Dim crd = Split(tmparr(1), "_")
                                        Try
                                            oChart.Application.DataSheet.Cells(crd(0), crd(1)).Value = tmparr(2)
                                        Catch ex As Exception
                                        End Try
                                    Next
                                    oChart.Application.Update()
                                    oChart.Application.Quit()


...and after these loops I release all objects through:

        Try
            System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
        Catch
        Finally
            o = Nothing
        End Try


Is it OK to create an instance of PowerPoint within the loop? Should I declare PPT with

oPPT = CreateObject("Powerpoint.application")

instead?

Thanks,
Daniel
0
Comment
Question by:sveshi
1 Comment
 
LVL 6

Accepted Solution

by:
david_barker earned 750 total points
ID: 12378390
I would try releasing each object separately, ie
  oApp.Close  'or whatever
  Set oApp=Nothing
Try releasing objects as soon as you have finished with them (if you don't need them anymore, like an oPres you have created and finished with), or keep them open (if you need them all the time, like with oApp). I guess your problems are related with that.

The following
  oPPT = CreateObject("Powerpoint.application")
shouldn't help. It's just another way of creating the instance (late binding vs. early binding).
Stick with your method of declaring types objects, I don't think it's related with the problem.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Manually copying shapes and their assigned macros one by one to a new location can be tedious, but if you use the Excel utility workbook attached to this article, the process will be much quicker and easier.
I tried to use the SharePoint app to Import a Spreadsheet and import an Excel sheet into a Team site made in SharePoint 2016. But that just resulted in getting an error message 'Unknown Error'...
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

599 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