• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 24. Visio Automation and Microso... > Getting Data from PowerPoint

Getting Data from PowerPoint

It is possible to take information from a PowerPoint document and use it to build a Visio diagram. The example below looks at an existing PowerPoint presentation and counts the number of slides. For each slide, it takes the title and bullet text and uses them to pass to Visio. Visio receives them and creates a new shape for each, sizing each appropriately, based on the quantity of text. Visio then connects each SmartShape symbol to create a flow diagram of the PowerPoint presentation (see Listing 24.3).

Listing 24.3. Analyzing a PowerPoint Presentation as a Visio Flowchart

Public Sub PowerPointAnalysis()
    Dim pagObj As Visio.Page
    Dim shpObj As Visio.Shape
    Dim shpObjPast As Visio.Shape
    Dim shpObjConn As Visio.Shape
    Dim celObj As Visio.Cell
    Dim pptObjApp As PowerPoint.Application
    Dim pptObjPres As PowerPoint.Presentation
    Dim intPptSlideCount As Integer
    Dim pptObjPptSlide As PowerPoint.Slide
    Dim intPptShapeCount As Integer
    Dim pptObjSlideShp As PowerPoint.Shape
    Dim szTextHolder As String
    Dim intFirstFlag As Integer
    intFirstFlag = 1
    Set pagObj = Visio.ActivePage
    Set pptObjApp = CreateObject("PowerPoint.Application")
    pptObjApp.Visible = msoTrue
    Set pptObjPres = pptObjApp.Presentations.Open("d:\Book-Macmillan\History.PPT")
    For intPptSlideCount = 1 To pptObjPres.Slides.Count
        Set pptObjPptSlide = pptObjPres.Slides(intPptSlideCount)
        szTextHolder = ""
        For intPptShapeCount = 1 To pptObjPptSlide.Shapes.Count
            Set pptObjSlideShp = pptObjPptSlide.Shapes(intPptShapeCount)
            If pptObjSlideShp.Type = msoPlaceholder Then
                szTextHolder = szTextHolder & pptObjSlideShp.TextFrame.TextRange & vbCrLf
            End If
        Next intPptShapeCount
        If intFirstFlag = 1 Then
            Debug.Print "first Time through"
        Else
            Set shpObjPast = shpObj
        End If
        Set shpObj = pagObj.DrawRectangle((pagObj.PageSheet.Cells("PageWidth").Result(visNumber) / 2) - 1, (pagObj.PageSheet.Cells("PageHeight").Result(visNumber) / 2) + 1, (pagObj.PageSheet.Cells("PageWidth").Result(visNumber) / 2) + 1, (pagObj.PageSheet.Cells("PageHeight").Result(visNumber) / 2) - 1)
        shpObj.Text = szTextHolder
        Set celObj = shpObj.Cells("Width")
        celObj.Formula = "=GUARD(TEXTWIDTH(TheText))"
        Set celObj = shpObj.Cells("Height")
        celObj.Formula = "=GUARD(TEXTHEIGHT(TheText, Width))"
        shpObj.AddNamedRow visSectionConnectionPts, visRowConnectionPts, 0
        Set celObj = shpObj.CellsSRC(visSectionConnectionPts, visRowConnectionPts, visCnnctX)
        celObj.Formula = "=Width*0.5"
        Set celObj = shpObj.CellsSRC(visSectionConnectionPts, visRowConnectionPts, visCnnctY)
        celObj.Formula = "=Height*1"
        shpObj.AddNamedRow visSectionConnectionPts, visRowConnectionPts + 1, 0
        Set celObj = shpObj.CellsSRC(visSectionConnectionPts, visRowConnectionPts + 1, visCnnctX)
        celObj.Formula = "=Width*0.5"
        Set celObj = shpObj.CellsSRC(visSectionConnectionPts, visRowConnectionPts + 1, visCnnctY)
        celObj.Formula = "=Height*0"
        Set celObj = shpObj.Cells("LocPinY")
        celObj.Formula = "=Height*1"
        Set celObj = shpObj.Cells("PinY")
        If intFirstFlag = 1 Then
            celObj.Formula = pagObj.PageSheet.Cells("PageHeight").Result(visNumber) - 1
        Else
            celObj.Formula = shpObjPast.Cells("PinY").Result(visNumber) - 
(shpObjPast.Cells("Height").Result(visNumber) + 1)
            Set shpObjConn = pagObj.DrawLine(1, 2, 1, 1)
            Set celObj = shpObjConn.Cells("BeginX")
            celObj.GlueTo shpObjPast.Cells("Connections.X2")
            Set celObj = shpObjConn.Cells("EndX")
            celObj.GlueTo shpObj.Cells("Connections.X1")
        End If
        intFirstFlag = 0
    Next intPptSlideCount
    Visio.ActiveWindow.Selection.DeselectAll
End Sub


					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint