none
Type Mismatch when addShape used to create Shape in PowerPoint using VBA for MS Project RRS feed

  • Question

  • I am used to writing VBA for Excel. I am being asked to right code for MS Project this time.  I have run into a number of circumstances where I can't get code to work in MS Project the way it does in Excel.  But my latest one I can't make a work-around for. I am trying to add a shape that isn't just a straight text box into a powerpoint presentation using the "Set" command so that I can change formatting, text, etc after placing it.  If I run this code using a VBA window that I have opened in Powerpoint it works fine, but if I do from MS Project, I get a  "Run-Time error '13':  Type Mismatch".   Under "Tools --> Reference" I have made sure that all the things checked in Powerpoint are also checked in MS Project.  I am at my wit's end.  Please help.  Even if to point me into a different place to post this question if I am in the wrong place.  Thanks in advance.  PS: I selected the VB.Net programing language when I inserted the code, but not sure this is correct for VBA.

    Sub make_shape()
    Dim objPPApp As Object
    Dim objPresentation As Object
    Dim objSlide As Object
    Dim objSuc As Shape
    Dim objBar As Object
            Set objPPApp = CreateObject("PowerPoint.Application")
            objPPApp.Visible = msoTrue
            Set objPresentation = objPPApp.Presentations.Add
            Set objSlide = objPresentation.Slides.Add(1, ppLayoutTitle)
            
    '       This works
            Set objBar = objSlide.Shapes.AddShape(msoTextOrientationHorizontal, 100, 100, 100, 100)
    '       This works
            objSlide.Shapes.AddShape Type:=msoShapeChevron, left:=50, top:=50, width:=50, height:=50
            
    '       This doesn't if run from MS Project, does work if run straight from macro within Powerpoint.  Very frustrating.  HELP!
            Set objSuc = objSlide.Shapes.AddShape(msoShapeChevron, 50, 50, 50, 50)
            
    End Sub

    Monday, February 4, 2013 8:23 PM

Answers

All replies