Method to export drawing to Powerpoint?

Started by John Distai, November 23, 2010, 04:20:09 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

John Distai

Hi.  I have a large drawing (130 pages) that is best viewed as a flip book.  I need to make this drawing available to non-Visio users.  Powerpoint works well for presenting items in a flip-book-type fashion.  I could copy each Visio page to PPT, but that would take all day.  Does anyone have a relatively easy way to export the pages of a Visio drawing into the pages of a PPT file?

Thanks!

Paul Herber

If you save all the pages as images could you then import all the images into a PPT slide show?
I have a utility that will save all the pages for you:
http://www.sandrila.co.uk/visio-utilities/?id=117
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

aledlund

you might try a macro like this

al



'
'
'
Public Sub generatePowerPoint()
   
    Dim visDocument As Visio.Document
    Dim visPage As Visio.Page
   
    Dim ppApp As PowerPoint.Application
    Dim ppSlide As PowerPoint.Slide
    Dim iObjCtr As Integer
    Dim iConCtr As Integer
    Dim iPagCtr As Integer
    Dim strForeground As String
    Dim strBackground As String
    Dim shpGroup As Visio.Shape
   
    Const MAX_SLIDES As Long = 250
    Const DEFAULT_AUTO_LAYOUT As Long = ppLayoutBlank
    Dim lLastSlide As Long
    lLastSlide = 1
    Dim lToCreate As Long
    lToCreate = 10
    Dim lResult As Long
    Dim Continue As Boolean
    Dim strResult As String
   
    On Error GoTo ErrHandler
    Err.Clear

    Set visDocument = Visio.ActiveDocument

    ' start powerpoint
    Set ppApp = New PowerPoint.Application
    ' make it visible
    ppApp.Visible = True
    ' create the presentation
    Dim ppPres As PowerPoint.Presentation
    Set ppPres = ppApp.Presentations.Add(msoTrue)
   
    lLastSlide = ppPres.Slides.Count
   
    'first we create the pages in the presentation
    For iPagCtr = 1 To visDocument.Pages.Count
        ' we dont want to include the background slides
        If visDocument.Pages(iPagCtr).Background = False Then
            lLastSlide = lLastSlide + 1
            ppPres.Slides.Add lLastSlide, ppLayoutBlank
                If Err.Number <> 0 Then
                    strResult = "Unable to add new slides " & Err.Description
                    Debug.Print strResult & " Page " & iPagCtr
                End
                End If ' test for slide being created
        End If ' test for background
    Next iPagCtr

    ' now we populate the pages in the presentation
    For iPagCtr = 1 To visDocument.Pages.Count
        ' Debug.Print "powerpoint page " & iPagCtr
        strForeground = ""
        strBackground = ""
        If visDocument.Pages(iPagCtr).Background = False Then
            ' move page to active window
            strForeground = visDocument.Pages(iPagCtr).Name
                'If Not (visDocument.Pages(iPagCtr).BackPage Is Nothing) Then
                '    strBackground = visDocument.Pages(iPagCtr).BackPage
                ' we can add code here to add background to the slide
                ' ActiveWindow.Page = strBackground
                ' but not today
                'Else
                '    strBackground = "NoBackground"
                'End If
            ActiveWindow.Page = strForeground
            ActiveWindow.SelectAll

           
            ActiveWindow.Group
           
            Set shpGroup = ActivePage.Shapes.Item(ActivePage.Shapes.Count)
            ' Debug.Print "powerpoint objects " & ActivePage.Shapes.Count
            ' copy selected items to clipboard
            ActiveWindow.Copy
            ' Debug.Print "copied"
            ' Paste Visio drawing from the clipboard to Powerpoint correct slide
            ppPres.Slides.Item(iPagCtr).Shapes.Paste
            ' now paste the page name into the slides footer as a label
            ppPres.Slides.Item(iPagCtr).HeadersFooters.Footer.Text = strForeground
            DoEvents
            ' Debug.Print "pasted"
            ' now let's ungroup them
            shpGroup.Ungroup
            ' Debug.Print "ungrouped"
            ' deselect the objects so we dont get confused
            ActiveWindow.DeselectAll
            ' give the system back some time to get things done
        End If
        DoEvents
    Next iPagCtr
   
ExitHandler:
    Exit Sub

ErrHandler:

    If Err <> 0 Then
        Debug.Print "Error in powerpoint " & Err & " " & Err.Description
        Resume Next
    End If

   
End Sub



John Distai

Thank you.  Unfortunately, I tried it and I received a "Compile error: User defined type not defined" when it came to the line "Dim ppApp AS Powerpoint.Application".  Any idea how to correct this?

Thanks!

aledlund

john,
apologies. Since it calls powerpoint you should make sure that when in the vba editor that you go to Tools => References and include the powerpoint that is installed on your system (microsoft powerpoint object library).
al

John Distai

This is exactly what I needed!  Thank you so much!

Visio Guy

Possibly related article:

Export All Pages in Document

This code snippet will help you to export all the pages in a Visio document as separate image files. Perhaps a slide-show app can utilize images as well as PowerPoint slides? I've never looked into it, but it seems a reasonable thing to do.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

fads

Hi Al,

I'm new to this world. Your above code is great and works brilliantly. I have a challenge where I would like to append visio into an existing powerpoint deck rather than creating a new ppt. Further would be really good to specify a slide number.

Thanks a lot,

SubPlanner

aledlund, Happy new year.
Is there a way to modify your code?
I need to export Visio drawings that are a standard 8-1/2 X 11 (Landscape) to a new PowerPoint. Your code does that well, but the height is a little larger than 8-1/2 for some reason. I can easily create an on open macro to correct the height inside PP, but the export would have to go to that macro enabled PP. Would be easier to have the height set when exporting from Visio.

I would love to be able to use Paul Herbers utilities but, my company will not let us download stuff like that to our intranet.  :-\

Any help you can offer would be greatly appreciated.

SubPlanner

aledlund

SubPlanner,
I would first check the size of the pages in your Visio document, since the copy is a straight forward group then copy to clipboard. Are you using a metric page size in the drawing and attempting top place it into a US version of powerpoint? Page sizes within Visio can be manipulated both manually and via VBA but we probably would want to understand why they are appearing in powerpoint as a 'wrong size' first.
Al Edlund

SubPlanner

I have the Visio drawing set to 8.5 X 11
It looks like what is happening is the actual drawing within the Visio document shows up in PP as the 8.5 X 11 and any items in the margins close to the edges go over and make it look like I need to adjust.
I included a snapshot of what it looks like when it gets into PP.
      PP in background and Visio doc in foreground.

When I do a print preview in Visio, I get the whole document in the with margins and date info on top right.

SubPlanner



SubPlanner

I wanted to add this in.
It looks like the default size of the blank PP I a little small.
See insert.

SubPlanner

SubPlanner

OMG. Now I find out if I have a protected master that makes up the background of all my pages, Then I make new pages with that background, the only thing that goes into PP are items I placed onto the new page and the background does not show up in PP.    :'(

SubPlanner

FlowerGirl

I saw this posted and it looks like what I need to accomplish an export to PP.

My only problem is my Visio slides are 11 x 17 and the code listed in this post exports to PP in an 8-1/2 X 11 format.
Is there a way to alter the code so when I export the Visio slides out, the receiving PP will be a 11 x 17 format and my Visio slides will fit and look good?


Thanks for the help as always.

FlowerGirl

SubPlanner

aledlund,
                  I have been using this code you posted and it works nicely, but it won't ungroup my separate shapes after pasting into PPT.

Is there something I am missing.

Thanks for you time SubPlanner