Consulting

Results 1 to 3 of 3

Thread: .Addpicture adds the picture to a placeholder rather as a new shape

  1. #1
    VBAX Newbie
    Joined
    Sep 2013
    Posts
    3
    Location

    .Addpicture adds the picture to a placeholder rather as a new shape

    I have a vba script which creates slides based on the contents of a Word file. The steps are:


    • add a new slide (mySlide). It has placeholders for a title and bodytext
    • copy text from the Word file to the title and bodytext.
    • add a picture using mySlide.Shapes.AddPicture Normally this works fine and creates 3 shapes which I can then size as required.

    However if the bodytext is empty the picture is added to the bodytext shape rather than as a new shape which complicates further processing considerably.

    How can I ensure .AddPicture always creates a third shape on the slide?


  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    I'm assuming you have 2007 or later?

    The problem is you almost certainly DON'T have Title and Bodytext ( you can create this but it's not usually standard) You probably have Title and CONTENT.

    Since Microsoft know best - There's a content placeholder and he's adding content. No brainer!

    Ways to get around this is either create a now custom layout thet does have a Text Placeholder OR

    Sub addPic()
    Dim oshp As Shape
    Dim osld As Slide
    On Error Resume Next
    Set osld = ActiveWindow.Selection.SlideRange(1)
    If Err <> 0 Then Exit Sub
    On Error GoTo 0
    For Each oshp In osld.Shapes
    If oshp.Type = msoPlaceholder Then
    If oshp.PlaceholderFormat.Type = ppPlaceholderObject Then
    If Not oshp.TextFrame.HasText Then oshp.TextFrame.TextRange = "DUMMY"
    End If
    End If
    Next oshp
    osld.Shapes.AddPicture FileName:="C:\Users\John\Desktop\Pic1.jpg", LinkToFile:=False, SaveWithDocument:=True, Left:=10, Top:=10
    For Each oshp In osld.Shapes
    If oshp.Type = msoPlaceholder Then
    If oshp.PlaceholderFormat.Type = ppPlaceholderObject Then
    If oshp.TextFrame.TextRange = "DUMMY" Then oshp.TextFrame.DeleteText
    End If
    End If
    Next oshp
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Newbie
    Joined
    Sep 2013
    Posts
    3
    Location

    Thanks

    Thanks for the response. Its not very elegant (thanks Microsoft) but it will work and save me a lot of other problems. You were right it is a default Title/Content slide - I was sloppy with my wording.

Posting Permissions

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