Share via

vba error "sub or function not defined" in ppt 2007

Anonymous
2012-03-22T21:17:11+00:00

Hello,

I am trying to learn VBA by using the book "Mastering VBA for Microsoft Office 2007" by Richard Mansfield. I successfully did the early exercises with Word and Excel, but when I try to run a macro in PowerPoint 2007, I get the error message "Compile Error: Sub or Function not defined".

I have saved the relevant project file with the .pptm extension, and have enabled all macros in PowerPoint. I know the macro's name appears properly spelled in the project. I went to the book's website (it's published by Sybex), but was unable to find anything there.

Any hints on why this doesn't work and how I can get it to work? I'm less interested in the actual procedure and more interested in just getting something to run so I can follow along with the exercises.

Thanks in advance for helping me learn!

tdp

The macro is as follows (see comment just below Sub name for the function of the macro):

Sub Add_Slide_and_Format_Placeholder() ‘ ‘ Sample macro that adds a slide, formats its placeholder, and adds text _ to it. Recorded 12/4/08 by Rodney Converse. ‘ ActiveWindow.View.GotoSlide Index:= _ ActivePresentation.Slides.Add(Index:=2, _ Layout:=ppLayoutText).SlideIndex ActiveWindow.Selection.SlideRange.Layout = ppLayoutTitle

ActiveWindow.Selection.SlideRange.Shapes(1).Select With ActiveWindow.Selection.ShapeRange .IncrementLeft -6# .IncrementTop -125.75 End With ActiveWindow.Selection.ShapeRange.ScaleHeight 1.56, msoFalse, _ msoScaleFromTopLeft

ActiveWindow.Selection.SlideRange.Shapes(1).Select

ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Select

ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters _ (Start:=1, Length:=0).Select With ActiveWindow.Selection.TextRange .Text = “The quick brown dog jumped over a lazy fox” With .Font .Name = “Arial” .Size = 44 .Bold = msoFalse .Italic = msoFalse .Underline = msoFalse .Shadow = msoFalse .Emboss = msoFalse .BaselineOffset = 0 .AutoRotateNumbers = msoFalse .Color.SchemeColor = ppTitle End With End With

ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters _ (Start:=1, Length:=42).Select With ActiveWindow.Selection.TextRange.Font .Name = “Impact” .Size = 54 .Bold = msoFalse .Italic = msoFalse .Underline = msoFalse .Shadow = msoFalse .Emboss = msoFalse .BaselineOffset = 0 .AutoRotateNumbers = msoFalse .Color.SchemeColor = ppTitle End With End Sub

Microsoft 365 and Office | PowerPoint | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2012-03-23T05:57:47+00:00

    Hi,

    Try below formatted and optimized code, please:

    Sub Add_Slide_and_Format_Placeholder()

        'Sample macro that adds a slide, formats its placeholder, and adds text _ to it. Recorded 12/4/08 by Rodney Converse.

        With ActiveWindow

            .View.GotoSlide Index:=ActivePresentation.Slides.Add(Index:=2, _

            Layout:=ppLayoutText).SlideIndex

            .Selection.SlideRange.Layout = ppLayoutTitle

            .Selection.SlideRange.Shapes(1).Select

        End With

        With ActiveWindow.Selection

            .ShapeRange.IncrementLeft -6#

            .ShapeRange.IncrementTop -125.75

            .ShapeRange.ScaleHeight 1.56, msoFalse, msoScaleFromTopLeft

            .SlideRange.Shapes(1).Select

            .ShapeRange.TextFrame.TextRange.Select

            .ShapeRange.TextFrame.TextRange.Characters(Start:=1, Length:=0).Select

        End With

        With ActiveWindow.Selection.TextRange

            .Text = "The quick brown dog jumped over a lazy fox"

            With .Font

                .Name = "Arial"

                .Size = 44

                .Bold = msoFalse

                .Italic = msoFalse

                .Underline = msoFalse

                .Shadow = msoFalse

                .Emboss = msoFalse

                .BaselineOffset = 0

                .AutoRotateNumbers = msoFalse

                .Color.SchemeColor = ppTitle

            End With

        End With

        With ActiveWindow.Selection

            .ShapeRange.TextFrame.TextRange.Characters(Start:=1, Length:=42).Select

            With .TextRange.Font

                .Name = "Impact"

                .Size = 54

                .Bold = msoFalse

                .Italic = msoFalse

                .Underline = msoFalse

                .Shadow = msoFalse

                .Emboss = msoFalse

                .BaselineOffset = 0

                .AutoRotateNumbers = msoFalse

                .Color.SchemeColor = ppTitle

            End With

        End With

    End Sub

    PS:

    When I test your code in PowerPoint 2007 and 2010, it all works OK! So I think the error is caused by your code format.

    Cheers,

    Cristin

    Was this answer helpful?

    0 comments No comments