Consulting

Results 1 to 5 of 5

Thread: Coding works for WORD but not POWERPOINT, how should i modify it?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,096
    Location
    This is top of head code but might give you a pointer

    Sub PicWithCaption()
        Dim xFileDialog As FileDialog
        Dim xPath As String, xFile As String, xFileName As String
        Dim oSlide As Slide
        Dim oShape As Shape
        Dim i As Long, j As Long
        Set xFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
        xFileDialog.Title = "Select a folder with pictures"
        If xFileDialog.Show = -1 Then
            xPath = xFileDialog.SelectedItems(1)
            If xPath <> "" Then
                xFile = Dir(xPath & "\*.*")
                 j = 0
                Do While xFile <> ""
                    If UCase(Right(xFile, 3)) = "PNG" Or _
                    UCase(Right(xFile, 3)) = "TIF" Or _
                    UCase(Right(xFile, 3)) = "JPG" Or _
                    UCase(Right(xFile, 4)) = "JPEG" Or _
                    UCase(Right(xFile, 3)) = "GIF" Or _
                    UCase(Right(xFile, 3)) = "BMP" Then
                    xFileName = Left(xFile, Len(xFile) - 4)
                    If j Mod 6 = 0 Then
                        Set oSlide = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
                        ActiveWindow.View.GotoSlide oSlide.SlideIndex
                   End If
                   i = j Mod 3
                   If j Mod 6 < 3 Then
                       Set oShape = oSlide.Shapes.AddPicture(FileName:=xPath & "\" & xFile, _
                       LinkToFile:=msoFalse, _
                       SaveWithDocument:=msoTrue, _
                       Left:=100 + i * 150, _
                       Top:=100)
                       oShape.LockAspectRatio = msoCTrue
                       oShape.Width = 120
                       oShape.Select False
                       Set oShape = oSlide.Shapes.AddTextbox(msoTextOrientationHorizontal, _
                       Left:=100 + i * 150, _
                       Top:=oShape.Top + oShape.Height + 10, _
                       Width:=120, _
                       Height:=20)
                       oShape.Select False
                       oShape.TextFrame.TextRange.Text = xFileName
                       oShape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
                    Else
                        Set oShape = oSlide.Shapes.AddPicture(FileName:=xPath & "\" & xFile, _
                        LinkToFile:=msoFalse, _
                        SaveWithDocument:=msoTrue, _
                        Left:=100 + i * 150, _
                        Top:=250)
                        oShape.LockAspectRatio = msoCTrue
                        oShape.Width = 120
                        oShape.Select False
                        Set oShape = oSlide.Shapes.AddTextbox(msoTextOrientationHorizontal, _
                        Left:=100 + i * 150, _
                        Top:=oShape.Top + oShape.Height + 10, _
                        Width:=120, _
                        Height:=20)
                        oShape.TextFrame.TextRange.Text = xFileName
                        oShape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
                        oShape.Select False
                    End If
                    j = j + 1
                    If j Mod 6 = 0 And j <> 0 Then
                        With ActiveWindow.Selection.ShapeRange.Group
                            .Left = ActivePresentation.PageSetup.SlideWidth / 2 - .Width / 2
                            .Ungroup
                         End With
                      End If.        
                   End If
                   xFile = Dir()
               Loop
            End If
        End If
    End Sub
    Last edited by Aussiebear; 03-02-2025 at 04:38 AM.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

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