How do I run the following code to export visio to powerpoint? I am a newbie to macro's.

R

Robert

I tried setting up a macro in visio and running it but it gave me a
compile error when it reached: Dim ppApp As PowerPoint.Application
Thanks in advance for your help.

Public Sub subGeneratePowerPoint()


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 powerpoint_err
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
MsgBox strResult, vbCritical, "Error Adding Slides"

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


powerpoint_exit:
Exit Sub


powerpoint_err:


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


End Sub
 
J

John Marshall, MVP

VBA has a limited number of Object libraries preselected. If you want to use
other libraries you have to add the reference.

In the VBA editor choose Tools --> References. It will show the object
libraries it is using. Scroll down to Microsoft Project 11.0 Object Library
and add a check.

John... Visio MVP

Need stencils or ideas? http://www.mvps.org/visio/3rdparty.htm
Need VBA examples? http://www.mvps.org/visio/VBA.htm
Common Visio Questions http://www.mvps.org/visio/common_questions.htm
Visio Wishlist http://www.mvps.org/visio/wish_list.htm
 
M

Mark Nelson [MS]

Or maybe even the PowerPoint 11.0 Object Library, John. :p

--
Mark Nelson
Office Graphics - Visio
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top