Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-10-21
1
Medium Priority
?
348 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
[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
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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
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 normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

636 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