Results 1 to 6 of 6
  1. #1
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have an Excel workbook which writes data to PowerPoint. I need it to work for both Office 2003 and Office 2007. In the VBA references I added MS PowerPoint 11.0 Object Library and it works for me in both Office versions, however when I give it to another person, they can't run it in Office 2003 without generating an error. How can I get around this so that it works in both versions of Office?

    Deb

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You could use late binding, i.e.:

    1) Declare all PowerPoint objects as Object instead of as a specific type, for example

    Dim ppApp As Object

    instead of

    Dim ppApp As PowerPoint.Application

    2) Replace all PowerPoint constants with their values, for example replace ppLayoutBlank with 12. You can look up the value of these constants in the Object Browser.

    3) Remove the reference to the Microsoft PowerPoint n.0 Object Library.

  3. #3
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I must be doing it wrong because it's not working. I removed the reference to PowerPoint 11. Here's the code with changes commented out. I had a reference to Shapes but commented it out - I still need it though to write to the slide title. I gets hung up at first use of the objPres variable.

    [codebox]Public Sub CopyToPPT()
    Dim objPPT As Object ' PowerPoint.Application
    Dim objPres As Object ' PowerPoint.Presentation
    Dim tempPath As String

    Set objPres = objPPT.Presentations.Add(True) ' STOPS here

    ' use corporate template if installed
    tempPath = Application.TemplatesPath
    On Error GoTo MissingPOT
    objPres.ApplyTemplate (tempPath & "blank.pot")

    Dim rng As Range, k As Integer ', shp As PowerPoint.Shapes

    ' insert one slide per table in ascending order
    For k = MAX_GRADE To 1 Step -1
    Set rng = ThisWorkbook.Worksheets("T" & k).Range(GRID_SIZE)
    rng.CopyPicture

    With objPPT.ActiveWindow
    .Presentation.Slides.Add(Index:=1, Layout:=11).Select
    .View.Paste

    ' move the pasted table down a bit
    .Selection.ShapeRange.IncrementTop 34

    ' add title
    ' Set shp = .Selection.SlideRange.Shapes ' only 2 shapes on this slide
    ' shp(1).TextFrame.TextRange.Characters(1, 0).Text = "Grade Level " & Mid(rng.Parent.Name, 2)
    ' Set shp = Nothing

    End With
    Next k
    Set rng = Nothing

    ExitHandler:

    On Error Resume Next
    Set objPPT = Nothing
    Exit Sub


    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Err.Clear

    End Sub[/codebox]

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    [quote name='jujuraf' post='767926' date='27-Mar-2009 22:29']...I removed the reference to PowerPoint 11. ...[/quote]
    I think you need something along these lines to get the ball rolling:

    Code:
    Set objPPT = CreateObject("PowerPoint.Application")

  5. #5
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok yes, that makes sense ... I think I read up on late binding and now got it working. Yeh!! I did this:

    [codebox]
    Dim objPPT as Object

    Set objPPT = GetObject(, "PowerPoint.Application")

    If objPPT Is Nothing Then
    Set objPPT = CreateObject("PowerPoint.Application")

    If objPPT Is Nothing Then
    MsgBox "Error! Can not start PowerPoint", vbExclamation + vbOKOnly, "Action Canceled"
    Exit Sub
    End If
    End If
    [/codebox]

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    [quote name='jujuraf' post='767930' date='27-Mar-2009 23:37']Ok yes, that makes sense ... I think I read up on late binding and now got it working. Yeh!! I did this:[/quote]
    That looks good. You might need to disable error handling (On Error Resume Next) before the GetObject() and then reset error handling (On Error Goto 0) after your If structure. But you'll know if you need it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •