How to save shape groups as photo to fileDialog path with amended name












2














This is what I have for my macro so far (details on question below):



Sub saveWithLogo()
Dim fd As FileDialog
Dim directory As String
Dim vrtSelectedItem As Variant
Dim osld As Slide
Dim oPic As Shape
Dim osldGroup As Slide
Dim oshp As Shape
Dim logoPic As Shape
Dim i As Integer
Dim num_pics As Integer
Dim fso As New FileSystemObject
Dim fileName As String
Dim filePath As String

Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd 'Get pictures from file dialog, add logo to each picture
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
numPics = .SelectedItems.Count
fileName = fso.GetBaseName(vrtSelectedItem)
filePath = fso.GetParentFolderName(vrtSelectedItem)
Set osld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
Set oPic = osld.Shapes.AddPicture(vrtSelectedItem, msoFalse, msoTrue, 50, 50)
logoWidth = 6.18 * 28.3
logoHeight = 1.4 * 28.3
Set logoPic = osld.Shapes.AddPicture("C:PicturesLogo" & "logo.png", lsoFalse, msoTrue, 50, 50, logoWidth, logoHeight)
Next vrtSelectedItem
End If
End With

For i = 1 To numPics 'Groups pictures on slide
Set osldGroup = ActivePresentation.Slides(i)
ActivePresentation.Slides(i).Select
ActiveWindow.Selection.Unselect
For Each oshp In osldGroup.Shapes
If oshp.Type = msoPicture Then oshp.Select Replace:=False
Next oshp
With ActiveWindow.Selection.ShapeRange
If .Count > 1 Then .Group
End With

'ActivePresentation.Slides(i).Select
'Call ActiveWindow.Selection.SlideRange.Shapes.Export(filePath & fileName & "_with logo", ppShapeFormatJPG, 3072)

Next i

Set fd = Nothing
End Sub


From here I want to take the grouped photo from each slide and save it to the file location of the fd selected items and save each grouped photo as an amended version of the original selected item.



So if I have selected items: "photo1.jpg", "thisphoto.png" and "somedescriptivename.jpg" all from the same folder (say "C:Documentsmyprojectimages" I want it to save the new grouped photos to "C:Documentsmyprojectimages" as "photo1_with logo.jpg", "thisphoto_with logo.jpg", and "somedescriptivename_with logo.jpg".



Right now I can successfully get all the pictures onto slides and group them. I don't know how to get a unique string name for each vrtSelectedItem in .SelectedItems. I know I can change



 Dim fileName As String


to



 Dim fileName() As String


in order to save it that way but I don't know how to reference that in the for loop (fso.GetBaseName(vrtSelectedItem.Index)?). And I'm also getting the error "Compile error: Method or data member not found" when attempting to save the group.










share|improve this question



























    2














    This is what I have for my macro so far (details on question below):



    Sub saveWithLogo()
    Dim fd As FileDialog
    Dim directory As String
    Dim vrtSelectedItem As Variant
    Dim osld As Slide
    Dim oPic As Shape
    Dim osldGroup As Slide
    Dim oshp As Shape
    Dim logoPic As Shape
    Dim i As Integer
    Dim num_pics As Integer
    Dim fso As New FileSystemObject
    Dim fileName As String
    Dim filePath As String

    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    With fd 'Get pictures from file dialog, add logo to each picture
    If .Show = -1 Then
    For Each vrtSelectedItem In .SelectedItems
    numPics = .SelectedItems.Count
    fileName = fso.GetBaseName(vrtSelectedItem)
    filePath = fso.GetParentFolderName(vrtSelectedItem)
    Set osld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
    Set oPic = osld.Shapes.AddPicture(vrtSelectedItem, msoFalse, msoTrue, 50, 50)
    logoWidth = 6.18 * 28.3
    logoHeight = 1.4 * 28.3
    Set logoPic = osld.Shapes.AddPicture("C:PicturesLogo" & "logo.png", lsoFalse, msoTrue, 50, 50, logoWidth, logoHeight)
    Next vrtSelectedItem
    End If
    End With

    For i = 1 To numPics 'Groups pictures on slide
    Set osldGroup = ActivePresentation.Slides(i)
    ActivePresentation.Slides(i).Select
    ActiveWindow.Selection.Unselect
    For Each oshp In osldGroup.Shapes
    If oshp.Type = msoPicture Then oshp.Select Replace:=False
    Next oshp
    With ActiveWindow.Selection.ShapeRange
    If .Count > 1 Then .Group
    End With

    'ActivePresentation.Slides(i).Select
    'Call ActiveWindow.Selection.SlideRange.Shapes.Export(filePath & fileName & "_with logo", ppShapeFormatJPG, 3072)

    Next i

    Set fd = Nothing
    End Sub


    From here I want to take the grouped photo from each slide and save it to the file location of the fd selected items and save each grouped photo as an amended version of the original selected item.



    So if I have selected items: "photo1.jpg", "thisphoto.png" and "somedescriptivename.jpg" all from the same folder (say "C:Documentsmyprojectimages" I want it to save the new grouped photos to "C:Documentsmyprojectimages" as "photo1_with logo.jpg", "thisphoto_with logo.jpg", and "somedescriptivename_with logo.jpg".



    Right now I can successfully get all the pictures onto slides and group them. I don't know how to get a unique string name for each vrtSelectedItem in .SelectedItems. I know I can change



     Dim fileName As String


    to



     Dim fileName() As String


    in order to save it that way but I don't know how to reference that in the for loop (fso.GetBaseName(vrtSelectedItem.Index)?). And I'm also getting the error "Compile error: Method or data member not found" when attempting to save the group.










    share|improve this question

























      2












      2








      2







      This is what I have for my macro so far (details on question below):



      Sub saveWithLogo()
      Dim fd As FileDialog
      Dim directory As String
      Dim vrtSelectedItem As Variant
      Dim osld As Slide
      Dim oPic As Shape
      Dim osldGroup As Slide
      Dim oshp As Shape
      Dim logoPic As Shape
      Dim i As Integer
      Dim num_pics As Integer
      Dim fso As New FileSystemObject
      Dim fileName As String
      Dim filePath As String

      Set fd = Application.FileDialog(msoFileDialogFilePicker)
      With fd 'Get pictures from file dialog, add logo to each picture
      If .Show = -1 Then
      For Each vrtSelectedItem In .SelectedItems
      numPics = .SelectedItems.Count
      fileName = fso.GetBaseName(vrtSelectedItem)
      filePath = fso.GetParentFolderName(vrtSelectedItem)
      Set osld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
      Set oPic = osld.Shapes.AddPicture(vrtSelectedItem, msoFalse, msoTrue, 50, 50)
      logoWidth = 6.18 * 28.3
      logoHeight = 1.4 * 28.3
      Set logoPic = osld.Shapes.AddPicture("C:PicturesLogo" & "logo.png", lsoFalse, msoTrue, 50, 50, logoWidth, logoHeight)
      Next vrtSelectedItem
      End If
      End With

      For i = 1 To numPics 'Groups pictures on slide
      Set osldGroup = ActivePresentation.Slides(i)
      ActivePresentation.Slides(i).Select
      ActiveWindow.Selection.Unselect
      For Each oshp In osldGroup.Shapes
      If oshp.Type = msoPicture Then oshp.Select Replace:=False
      Next oshp
      With ActiveWindow.Selection.ShapeRange
      If .Count > 1 Then .Group
      End With

      'ActivePresentation.Slides(i).Select
      'Call ActiveWindow.Selection.SlideRange.Shapes.Export(filePath & fileName & "_with logo", ppShapeFormatJPG, 3072)

      Next i

      Set fd = Nothing
      End Sub


      From here I want to take the grouped photo from each slide and save it to the file location of the fd selected items and save each grouped photo as an amended version of the original selected item.



      So if I have selected items: "photo1.jpg", "thisphoto.png" and "somedescriptivename.jpg" all from the same folder (say "C:Documentsmyprojectimages" I want it to save the new grouped photos to "C:Documentsmyprojectimages" as "photo1_with logo.jpg", "thisphoto_with logo.jpg", and "somedescriptivename_with logo.jpg".



      Right now I can successfully get all the pictures onto slides and group them. I don't know how to get a unique string name for each vrtSelectedItem in .SelectedItems. I know I can change



       Dim fileName As String


      to



       Dim fileName() As String


      in order to save it that way but I don't know how to reference that in the for loop (fso.GetBaseName(vrtSelectedItem.Index)?). And I'm also getting the error "Compile error: Method or data member not found" when attempting to save the group.










      share|improve this question













      This is what I have for my macro so far (details on question below):



      Sub saveWithLogo()
      Dim fd As FileDialog
      Dim directory As String
      Dim vrtSelectedItem As Variant
      Dim osld As Slide
      Dim oPic As Shape
      Dim osldGroup As Slide
      Dim oshp As Shape
      Dim logoPic As Shape
      Dim i As Integer
      Dim num_pics As Integer
      Dim fso As New FileSystemObject
      Dim fileName As String
      Dim filePath As String

      Set fd = Application.FileDialog(msoFileDialogFilePicker)
      With fd 'Get pictures from file dialog, add logo to each picture
      If .Show = -1 Then
      For Each vrtSelectedItem In .SelectedItems
      numPics = .SelectedItems.Count
      fileName = fso.GetBaseName(vrtSelectedItem)
      filePath = fso.GetParentFolderName(vrtSelectedItem)
      Set osld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
      Set oPic = osld.Shapes.AddPicture(vrtSelectedItem, msoFalse, msoTrue, 50, 50)
      logoWidth = 6.18 * 28.3
      logoHeight = 1.4 * 28.3
      Set logoPic = osld.Shapes.AddPicture("C:PicturesLogo" & "logo.png", lsoFalse, msoTrue, 50, 50, logoWidth, logoHeight)
      Next vrtSelectedItem
      End If
      End With

      For i = 1 To numPics 'Groups pictures on slide
      Set osldGroup = ActivePresentation.Slides(i)
      ActivePresentation.Slides(i).Select
      ActiveWindow.Selection.Unselect
      For Each oshp In osldGroup.Shapes
      If oshp.Type = msoPicture Then oshp.Select Replace:=False
      Next oshp
      With ActiveWindow.Selection.ShapeRange
      If .Count > 1 Then .Group
      End With

      'ActivePresentation.Slides(i).Select
      'Call ActiveWindow.Selection.SlideRange.Shapes.Export(filePath & fileName & "_with logo", ppShapeFormatJPG, 3072)

      Next i

      Set fd = Nothing
      End Sub


      From here I want to take the grouped photo from each slide and save it to the file location of the fd selected items and save each grouped photo as an amended version of the original selected item.



      So if I have selected items: "photo1.jpg", "thisphoto.png" and "somedescriptivename.jpg" all from the same folder (say "C:Documentsmyprojectimages" I want it to save the new grouped photos to "C:Documentsmyprojectimages" as "photo1_with logo.jpg", "thisphoto_with logo.jpg", and "somedescriptivename_with logo.jpg".



      Right now I can successfully get all the pictures onto slides and group them. I don't know how to get a unique string name for each vrtSelectedItem in .SelectedItems. I know I can change



       Dim fileName As String


      to



       Dim fileName() As String


      in order to save it that way but I don't know how to reference that in the for loop (fso.GetBaseName(vrtSelectedItem.Index)?). And I'm also getting the error "Compile error: Method or data member not found" when attempting to save the group.







      vba powerpoint-vba






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 12 '18 at 22:14









      b.sauerb.sauer

      526




      526
























          2 Answers
          2






          active

          oldest

          votes


















          0














          It may solve the problem. It is not tried fully as Final Export method is throwing PowerPoint converter installation problem in my present system. But otherwise there is no error like "Compile error: Method or data member not found"



          May simply try collection



          Option Base 1 
          '
          '
          ' then in Declaration
          Dim FileName As New Collection
          Dim FilePath As New Collection
          Dim FinalName As String
          '
          '
          'the in For Each vrtSelectedItem In .SelectedItems

          FileName.Add fso.GetBaseName(vrtSelectedItem)
          FilePath.Add fso.GetParentFolderName(vrtSelectedItem)
          '
          '
          '
          ' then in For i = 1 To numPics after End With

          FinalName = FilePath(i) & "" & FileName(i) & "_with logo"
          ActivePresentation.Slides(i).Select
          'MsgBox FinalName
          ActivePresentation.Slides(i).Export FinalName , ppShapeFormatJPG, 3072


          Could not understand if you are placing earlier saved pictures in slides and placing logo on them? if it is that simple then may try simpler alternative with single loop



          Sub saveWithLogo()
          Dim fd As FileDialog
          Dim directory As String
          Dim vrtSelectedItem As Variant
          Dim osld As Slide
          Dim oPic As Shape
          Dim osldGroup As Slide
          Dim oshp As Shape
          Dim logoPic As Shape
          Dim i As Integer
          Dim num_pics As Integer
          Dim fso As New FileSystemObject
          Dim FileName As String
          Dim FilePath As String

          Set fd = Application.FileDialog(msoFileDialogFilePicker)
          With fd 'Get pictures from file dialog, add logo to each picture
          If .Show = -1 Then
          For Each vrtSelectedItem In .SelectedItems
          numPics = .SelectedItems.Count
          FileName = fso.GetBaseName(vrtSelectedItem)
          FilePath = fso.GetParentFolderName(vrtSelectedItem)
          Set osld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
          Set oPic = osld.Shapes.AddPicture(vrtSelectedItem, msoFalse, msoTrue, 50, 50)
          osldno = ActivePresentation.Slides.Count
          logoWidth = 6.18 * 28.3
          logoHeight = 1.4 * 28.3
          Set logoPic = osld.Shapes.AddPicture("C:foxpro2vtoolslogo.bmp", lsoFalse, msoTrue, 50, 50, logoWidth, logoHeight)
          osld.Select
          ActiveWindow.Selection.Unselect
          For Each oshp In osld.Shapes
          If oshp.Type = msoPicture Then oshp.Select Replace:=False
          Next oshp
          With ActiveWindow.Selection.ShapeRange
          If .Count > 1 Then .Group
          End With
          FinalName = FilePath & "" & FileName & "_with logo"
          'MsgBox FinalName
          osld.Export FinalName & "_with logo", ppShapeFormatJPG ' , 3072
          Next vrtSelectedItem
          End If
          End With

          Set fd = Nothing
          End Sub





          share|improve this answer































            0














            For the curios or those with the same problem. Here's the final successful macro with what I learned from Ahmed's Answer.



            I added image scaling since the output size was way smaller than the original.



            Sub saveWithLogo()

            Dim fd As FileDialog
            Dim directory As String
            Dim vrtSelectedItem As Variant
            Dim osld As Slide
            Dim oPic As Shape
            Dim osldGroup As Slide
            Dim oshp As Shape
            Dim logoPic As Shape
            Dim i As Integer
            Dim num_pics As Integer
            Dim fso As New FileSystemObject
            Dim fileName As New Collection
            Dim filePath As New Collection
            Dim finalName As String

            Set fd = Application.FileDialog(msoFileDialogFilePicker)
            With fd 'Get pictures from file dialog, add logo to each picture
            If .Show = -1 Then
            For Each vrtSelectedItem In .SelectedItems
            numPics = .SelectedItems.Count
            fileName.Add fso.GetBaseName(vrtSelectedItem)
            filePath.Add fso.GetParentFolderName(vrtSelectedItem)
            Set osld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
            Set oPic = osld.Shapes.AddPicture(vrtSelectedItem, msoFalse, msoTrue, 50, 50)
            With oPic
            .LockAspectRatio = msoTrue
            .ScaleWidth 1.875, msoTrue
            End With
            logoWidth = 6.18 * 28.3
            logoHeight = 1.4 * 28.3
            Set logoPic = osld.Shapes.AddPicture("C:PicturesLogo Images" & "logo.png", lsoFalse, msoTrue, 100, 85, logoWidth, logoHeight)
            With logoPic
            .LockAspectRatio = msoTrue
            .ScaleWidth 0.005 * oPic.Width, msoTrue
            End With
            Set oPic = Nothing
            Set logoPic = Nothing
            Next vrtSelectedItem
            End If
            End With

            For i = 1 To numPics 'Groups pictures on slide
            Set osldGroup = ActivePresentation.Slides(i)
            ActivePresentation.Slides(i).Select
            ActiveWindow.Selection.Unselect
            For Each oshp In osldGroup.Shapes
            If oshp.Type = msoPicture Then oshp.Select Replace:=False
            Next oshp
            With ActiveWindow.Selection.ShapeRange
            If .Count > 1 Then
            .Group
            End If
            End With
            Next i

            Dim ap As Presentation: Set ap = ActivePresentation
            Dim sl As Slide
            Dim shGroup As ShapeRange
            For Each sl In ap.Slides
            ActiveWindow.View.GotoSlide (sl.SlideIndex)
            sl.Shapes.SelectAll
            Set shGroup = ActiveWindow.Selection.ShapeRange
            shGroup.Export filePath(sl.SlideIndex) & "" & fileName(sl.SlideIndex) & "_with logo" & ".jpg", ppShapeFormatJPG, , , ppScaleXY
            Next

            Set fd = Nothing
            Dim v As Long
            For v = 1 To Application.ActivePresentation.Slides.Count
            ActivePresentation.Slides.Range(1).Delete
            Next v

            End Sub





            share|improve this answer





















              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270866%2fhow-to-save-shape-groups-as-photo-to-filedialog-path-with-amended-name%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              It may solve the problem. It is not tried fully as Final Export method is throwing PowerPoint converter installation problem in my present system. But otherwise there is no error like "Compile error: Method or data member not found"



              May simply try collection



              Option Base 1 
              '
              '
              ' then in Declaration
              Dim FileName As New Collection
              Dim FilePath As New Collection
              Dim FinalName As String
              '
              '
              'the in For Each vrtSelectedItem In .SelectedItems

              FileName.Add fso.GetBaseName(vrtSelectedItem)
              FilePath.Add fso.GetParentFolderName(vrtSelectedItem)
              '
              '
              '
              ' then in For i = 1 To numPics after End With

              FinalName = FilePath(i) & "" & FileName(i) & "_with logo"
              ActivePresentation.Slides(i).Select
              'MsgBox FinalName
              ActivePresentation.Slides(i).Export FinalName , ppShapeFormatJPG, 3072


              Could not understand if you are placing earlier saved pictures in slides and placing logo on them? if it is that simple then may try simpler alternative with single loop



              Sub saveWithLogo()
              Dim fd As FileDialog
              Dim directory As String
              Dim vrtSelectedItem As Variant
              Dim osld As Slide
              Dim oPic As Shape
              Dim osldGroup As Slide
              Dim oshp As Shape
              Dim logoPic As Shape
              Dim i As Integer
              Dim num_pics As Integer
              Dim fso As New FileSystemObject
              Dim FileName As String
              Dim FilePath As String

              Set fd = Application.FileDialog(msoFileDialogFilePicker)
              With fd 'Get pictures from file dialog, add logo to each picture
              If .Show = -1 Then
              For Each vrtSelectedItem In .SelectedItems
              numPics = .SelectedItems.Count
              FileName = fso.GetBaseName(vrtSelectedItem)
              FilePath = fso.GetParentFolderName(vrtSelectedItem)
              Set osld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
              Set oPic = osld.Shapes.AddPicture(vrtSelectedItem, msoFalse, msoTrue, 50, 50)
              osldno = ActivePresentation.Slides.Count
              logoWidth = 6.18 * 28.3
              logoHeight = 1.4 * 28.3
              Set logoPic = osld.Shapes.AddPicture("C:foxpro2vtoolslogo.bmp", lsoFalse, msoTrue, 50, 50, logoWidth, logoHeight)
              osld.Select
              ActiveWindow.Selection.Unselect
              For Each oshp In osld.Shapes
              If oshp.Type = msoPicture Then oshp.Select Replace:=False
              Next oshp
              With ActiveWindow.Selection.ShapeRange
              If .Count > 1 Then .Group
              End With
              FinalName = FilePath & "" & FileName & "_with logo"
              'MsgBox FinalName
              osld.Export FinalName & "_with logo", ppShapeFormatJPG ' , 3072
              Next vrtSelectedItem
              End If
              End With

              Set fd = Nothing
              End Sub





              share|improve this answer




























                0














                It may solve the problem. It is not tried fully as Final Export method is throwing PowerPoint converter installation problem in my present system. But otherwise there is no error like "Compile error: Method or data member not found"



                May simply try collection



                Option Base 1 
                '
                '
                ' then in Declaration
                Dim FileName As New Collection
                Dim FilePath As New Collection
                Dim FinalName As String
                '
                '
                'the in For Each vrtSelectedItem In .SelectedItems

                FileName.Add fso.GetBaseName(vrtSelectedItem)
                FilePath.Add fso.GetParentFolderName(vrtSelectedItem)
                '
                '
                '
                ' then in For i = 1 To numPics after End With

                FinalName = FilePath(i) & "" & FileName(i) & "_with logo"
                ActivePresentation.Slides(i).Select
                'MsgBox FinalName
                ActivePresentation.Slides(i).Export FinalName , ppShapeFormatJPG, 3072


                Could not understand if you are placing earlier saved pictures in slides and placing logo on them? if it is that simple then may try simpler alternative with single loop



                Sub saveWithLogo()
                Dim fd As FileDialog
                Dim directory As String
                Dim vrtSelectedItem As Variant
                Dim osld As Slide
                Dim oPic As Shape
                Dim osldGroup As Slide
                Dim oshp As Shape
                Dim logoPic As Shape
                Dim i As Integer
                Dim num_pics As Integer
                Dim fso As New FileSystemObject
                Dim FileName As String
                Dim FilePath As String

                Set fd = Application.FileDialog(msoFileDialogFilePicker)
                With fd 'Get pictures from file dialog, add logo to each picture
                If .Show = -1 Then
                For Each vrtSelectedItem In .SelectedItems
                numPics = .SelectedItems.Count
                FileName = fso.GetBaseName(vrtSelectedItem)
                FilePath = fso.GetParentFolderName(vrtSelectedItem)
                Set osld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
                Set oPic = osld.Shapes.AddPicture(vrtSelectedItem, msoFalse, msoTrue, 50, 50)
                osldno = ActivePresentation.Slides.Count
                logoWidth = 6.18 * 28.3
                logoHeight = 1.4 * 28.3
                Set logoPic = osld.Shapes.AddPicture("C:foxpro2vtoolslogo.bmp", lsoFalse, msoTrue, 50, 50, logoWidth, logoHeight)
                osld.Select
                ActiveWindow.Selection.Unselect
                For Each oshp In osld.Shapes
                If oshp.Type = msoPicture Then oshp.Select Replace:=False
                Next oshp
                With ActiveWindow.Selection.ShapeRange
                If .Count > 1 Then .Group
                End With
                FinalName = FilePath & "" & FileName & "_with logo"
                'MsgBox FinalName
                osld.Export FinalName & "_with logo", ppShapeFormatJPG ' , 3072
                Next vrtSelectedItem
                End If
                End With

                Set fd = Nothing
                End Sub





                share|improve this answer


























                  0












                  0








                  0






                  It may solve the problem. It is not tried fully as Final Export method is throwing PowerPoint converter installation problem in my present system. But otherwise there is no error like "Compile error: Method or data member not found"



                  May simply try collection



                  Option Base 1 
                  '
                  '
                  ' then in Declaration
                  Dim FileName As New Collection
                  Dim FilePath As New Collection
                  Dim FinalName As String
                  '
                  '
                  'the in For Each vrtSelectedItem In .SelectedItems

                  FileName.Add fso.GetBaseName(vrtSelectedItem)
                  FilePath.Add fso.GetParentFolderName(vrtSelectedItem)
                  '
                  '
                  '
                  ' then in For i = 1 To numPics after End With

                  FinalName = FilePath(i) & "" & FileName(i) & "_with logo"
                  ActivePresentation.Slides(i).Select
                  'MsgBox FinalName
                  ActivePresentation.Slides(i).Export FinalName , ppShapeFormatJPG, 3072


                  Could not understand if you are placing earlier saved pictures in slides and placing logo on them? if it is that simple then may try simpler alternative with single loop



                  Sub saveWithLogo()
                  Dim fd As FileDialog
                  Dim directory As String
                  Dim vrtSelectedItem As Variant
                  Dim osld As Slide
                  Dim oPic As Shape
                  Dim osldGroup As Slide
                  Dim oshp As Shape
                  Dim logoPic As Shape
                  Dim i As Integer
                  Dim num_pics As Integer
                  Dim fso As New FileSystemObject
                  Dim FileName As String
                  Dim FilePath As String

                  Set fd = Application.FileDialog(msoFileDialogFilePicker)
                  With fd 'Get pictures from file dialog, add logo to each picture
                  If .Show = -1 Then
                  For Each vrtSelectedItem In .SelectedItems
                  numPics = .SelectedItems.Count
                  FileName = fso.GetBaseName(vrtSelectedItem)
                  FilePath = fso.GetParentFolderName(vrtSelectedItem)
                  Set osld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
                  Set oPic = osld.Shapes.AddPicture(vrtSelectedItem, msoFalse, msoTrue, 50, 50)
                  osldno = ActivePresentation.Slides.Count
                  logoWidth = 6.18 * 28.3
                  logoHeight = 1.4 * 28.3
                  Set logoPic = osld.Shapes.AddPicture("C:foxpro2vtoolslogo.bmp", lsoFalse, msoTrue, 50, 50, logoWidth, logoHeight)
                  osld.Select
                  ActiveWindow.Selection.Unselect
                  For Each oshp In osld.Shapes
                  If oshp.Type = msoPicture Then oshp.Select Replace:=False
                  Next oshp
                  With ActiveWindow.Selection.ShapeRange
                  If .Count > 1 Then .Group
                  End With
                  FinalName = FilePath & "" & FileName & "_with logo"
                  'MsgBox FinalName
                  osld.Export FinalName & "_with logo", ppShapeFormatJPG ' , 3072
                  Next vrtSelectedItem
                  End If
                  End With

                  Set fd = Nothing
                  End Sub





                  share|improve this answer














                  It may solve the problem. It is not tried fully as Final Export method is throwing PowerPoint converter installation problem in my present system. But otherwise there is no error like "Compile error: Method or data member not found"



                  May simply try collection



                  Option Base 1 
                  '
                  '
                  ' then in Declaration
                  Dim FileName As New Collection
                  Dim FilePath As New Collection
                  Dim FinalName As String
                  '
                  '
                  'the in For Each vrtSelectedItem In .SelectedItems

                  FileName.Add fso.GetBaseName(vrtSelectedItem)
                  FilePath.Add fso.GetParentFolderName(vrtSelectedItem)
                  '
                  '
                  '
                  ' then in For i = 1 To numPics after End With

                  FinalName = FilePath(i) & "" & FileName(i) & "_with logo"
                  ActivePresentation.Slides(i).Select
                  'MsgBox FinalName
                  ActivePresentation.Slides(i).Export FinalName , ppShapeFormatJPG, 3072


                  Could not understand if you are placing earlier saved pictures in slides and placing logo on them? if it is that simple then may try simpler alternative with single loop



                  Sub saveWithLogo()
                  Dim fd As FileDialog
                  Dim directory As String
                  Dim vrtSelectedItem As Variant
                  Dim osld As Slide
                  Dim oPic As Shape
                  Dim osldGroup As Slide
                  Dim oshp As Shape
                  Dim logoPic As Shape
                  Dim i As Integer
                  Dim num_pics As Integer
                  Dim fso As New FileSystemObject
                  Dim FileName As String
                  Dim FilePath As String

                  Set fd = Application.FileDialog(msoFileDialogFilePicker)
                  With fd 'Get pictures from file dialog, add logo to each picture
                  If .Show = -1 Then
                  For Each vrtSelectedItem In .SelectedItems
                  numPics = .SelectedItems.Count
                  FileName = fso.GetBaseName(vrtSelectedItem)
                  FilePath = fso.GetParentFolderName(vrtSelectedItem)
                  Set osld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
                  Set oPic = osld.Shapes.AddPicture(vrtSelectedItem, msoFalse, msoTrue, 50, 50)
                  osldno = ActivePresentation.Slides.Count
                  logoWidth = 6.18 * 28.3
                  logoHeight = 1.4 * 28.3
                  Set logoPic = osld.Shapes.AddPicture("C:foxpro2vtoolslogo.bmp", lsoFalse, msoTrue, 50, 50, logoWidth, logoHeight)
                  osld.Select
                  ActiveWindow.Selection.Unselect
                  For Each oshp In osld.Shapes
                  If oshp.Type = msoPicture Then oshp.Select Replace:=False
                  Next oshp
                  With ActiveWindow.Selection.ShapeRange
                  If .Count > 1 Then .Group
                  End With
                  FinalName = FilePath & "" & FileName & "_with logo"
                  'MsgBox FinalName
                  osld.Export FinalName & "_with logo", ppShapeFormatJPG ' , 3072
                  Next vrtSelectedItem
                  End If
                  End With

                  Set fd = Nothing
                  End Sub






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 13 '18 at 8:25

























                  answered Nov 13 '18 at 8:18









                  Ahmed AUAhmed AU

                  77028




                  77028

























                      0














                      For the curios or those with the same problem. Here's the final successful macro with what I learned from Ahmed's Answer.



                      I added image scaling since the output size was way smaller than the original.



                      Sub saveWithLogo()

                      Dim fd As FileDialog
                      Dim directory As String
                      Dim vrtSelectedItem As Variant
                      Dim osld As Slide
                      Dim oPic As Shape
                      Dim osldGroup As Slide
                      Dim oshp As Shape
                      Dim logoPic As Shape
                      Dim i As Integer
                      Dim num_pics As Integer
                      Dim fso As New FileSystemObject
                      Dim fileName As New Collection
                      Dim filePath As New Collection
                      Dim finalName As String

                      Set fd = Application.FileDialog(msoFileDialogFilePicker)
                      With fd 'Get pictures from file dialog, add logo to each picture
                      If .Show = -1 Then
                      For Each vrtSelectedItem In .SelectedItems
                      numPics = .SelectedItems.Count
                      fileName.Add fso.GetBaseName(vrtSelectedItem)
                      filePath.Add fso.GetParentFolderName(vrtSelectedItem)
                      Set osld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
                      Set oPic = osld.Shapes.AddPicture(vrtSelectedItem, msoFalse, msoTrue, 50, 50)
                      With oPic
                      .LockAspectRatio = msoTrue
                      .ScaleWidth 1.875, msoTrue
                      End With
                      logoWidth = 6.18 * 28.3
                      logoHeight = 1.4 * 28.3
                      Set logoPic = osld.Shapes.AddPicture("C:PicturesLogo Images" & "logo.png", lsoFalse, msoTrue, 100, 85, logoWidth, logoHeight)
                      With logoPic
                      .LockAspectRatio = msoTrue
                      .ScaleWidth 0.005 * oPic.Width, msoTrue
                      End With
                      Set oPic = Nothing
                      Set logoPic = Nothing
                      Next vrtSelectedItem
                      End If
                      End With

                      For i = 1 To numPics 'Groups pictures on slide
                      Set osldGroup = ActivePresentation.Slides(i)
                      ActivePresentation.Slides(i).Select
                      ActiveWindow.Selection.Unselect
                      For Each oshp In osldGroup.Shapes
                      If oshp.Type = msoPicture Then oshp.Select Replace:=False
                      Next oshp
                      With ActiveWindow.Selection.ShapeRange
                      If .Count > 1 Then
                      .Group
                      End If
                      End With
                      Next i

                      Dim ap As Presentation: Set ap = ActivePresentation
                      Dim sl As Slide
                      Dim shGroup As ShapeRange
                      For Each sl In ap.Slides
                      ActiveWindow.View.GotoSlide (sl.SlideIndex)
                      sl.Shapes.SelectAll
                      Set shGroup = ActiveWindow.Selection.ShapeRange
                      shGroup.Export filePath(sl.SlideIndex) & "" & fileName(sl.SlideIndex) & "_with logo" & ".jpg", ppShapeFormatJPG, , , ppScaleXY
                      Next

                      Set fd = Nothing
                      Dim v As Long
                      For v = 1 To Application.ActivePresentation.Slides.Count
                      ActivePresentation.Slides.Range(1).Delete
                      Next v

                      End Sub





                      share|improve this answer


























                        0














                        For the curios or those with the same problem. Here's the final successful macro with what I learned from Ahmed's Answer.



                        I added image scaling since the output size was way smaller than the original.



                        Sub saveWithLogo()

                        Dim fd As FileDialog
                        Dim directory As String
                        Dim vrtSelectedItem As Variant
                        Dim osld As Slide
                        Dim oPic As Shape
                        Dim osldGroup As Slide
                        Dim oshp As Shape
                        Dim logoPic As Shape
                        Dim i As Integer
                        Dim num_pics As Integer
                        Dim fso As New FileSystemObject
                        Dim fileName As New Collection
                        Dim filePath As New Collection
                        Dim finalName As String

                        Set fd = Application.FileDialog(msoFileDialogFilePicker)
                        With fd 'Get pictures from file dialog, add logo to each picture
                        If .Show = -1 Then
                        For Each vrtSelectedItem In .SelectedItems
                        numPics = .SelectedItems.Count
                        fileName.Add fso.GetBaseName(vrtSelectedItem)
                        filePath.Add fso.GetParentFolderName(vrtSelectedItem)
                        Set osld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
                        Set oPic = osld.Shapes.AddPicture(vrtSelectedItem, msoFalse, msoTrue, 50, 50)
                        With oPic
                        .LockAspectRatio = msoTrue
                        .ScaleWidth 1.875, msoTrue
                        End With
                        logoWidth = 6.18 * 28.3
                        logoHeight = 1.4 * 28.3
                        Set logoPic = osld.Shapes.AddPicture("C:PicturesLogo Images" & "logo.png", lsoFalse, msoTrue, 100, 85, logoWidth, logoHeight)
                        With logoPic
                        .LockAspectRatio = msoTrue
                        .ScaleWidth 0.005 * oPic.Width, msoTrue
                        End With
                        Set oPic = Nothing
                        Set logoPic = Nothing
                        Next vrtSelectedItem
                        End If
                        End With

                        For i = 1 To numPics 'Groups pictures on slide
                        Set osldGroup = ActivePresentation.Slides(i)
                        ActivePresentation.Slides(i).Select
                        ActiveWindow.Selection.Unselect
                        For Each oshp In osldGroup.Shapes
                        If oshp.Type = msoPicture Then oshp.Select Replace:=False
                        Next oshp
                        With ActiveWindow.Selection.ShapeRange
                        If .Count > 1 Then
                        .Group
                        End If
                        End With
                        Next i

                        Dim ap As Presentation: Set ap = ActivePresentation
                        Dim sl As Slide
                        Dim shGroup As ShapeRange
                        For Each sl In ap.Slides
                        ActiveWindow.View.GotoSlide (sl.SlideIndex)
                        sl.Shapes.SelectAll
                        Set shGroup = ActiveWindow.Selection.ShapeRange
                        shGroup.Export filePath(sl.SlideIndex) & "" & fileName(sl.SlideIndex) & "_with logo" & ".jpg", ppShapeFormatJPG, , , ppScaleXY
                        Next

                        Set fd = Nothing
                        Dim v As Long
                        For v = 1 To Application.ActivePresentation.Slides.Count
                        ActivePresentation.Slides.Range(1).Delete
                        Next v

                        End Sub





                        share|improve this answer
























                          0












                          0








                          0






                          For the curios or those with the same problem. Here's the final successful macro with what I learned from Ahmed's Answer.



                          I added image scaling since the output size was way smaller than the original.



                          Sub saveWithLogo()

                          Dim fd As FileDialog
                          Dim directory As String
                          Dim vrtSelectedItem As Variant
                          Dim osld As Slide
                          Dim oPic As Shape
                          Dim osldGroup As Slide
                          Dim oshp As Shape
                          Dim logoPic As Shape
                          Dim i As Integer
                          Dim num_pics As Integer
                          Dim fso As New FileSystemObject
                          Dim fileName As New Collection
                          Dim filePath As New Collection
                          Dim finalName As String

                          Set fd = Application.FileDialog(msoFileDialogFilePicker)
                          With fd 'Get pictures from file dialog, add logo to each picture
                          If .Show = -1 Then
                          For Each vrtSelectedItem In .SelectedItems
                          numPics = .SelectedItems.Count
                          fileName.Add fso.GetBaseName(vrtSelectedItem)
                          filePath.Add fso.GetParentFolderName(vrtSelectedItem)
                          Set osld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
                          Set oPic = osld.Shapes.AddPicture(vrtSelectedItem, msoFalse, msoTrue, 50, 50)
                          With oPic
                          .LockAspectRatio = msoTrue
                          .ScaleWidth 1.875, msoTrue
                          End With
                          logoWidth = 6.18 * 28.3
                          logoHeight = 1.4 * 28.3
                          Set logoPic = osld.Shapes.AddPicture("C:PicturesLogo Images" & "logo.png", lsoFalse, msoTrue, 100, 85, logoWidth, logoHeight)
                          With logoPic
                          .LockAspectRatio = msoTrue
                          .ScaleWidth 0.005 * oPic.Width, msoTrue
                          End With
                          Set oPic = Nothing
                          Set logoPic = Nothing
                          Next vrtSelectedItem
                          End If
                          End With

                          For i = 1 To numPics 'Groups pictures on slide
                          Set osldGroup = ActivePresentation.Slides(i)
                          ActivePresentation.Slides(i).Select
                          ActiveWindow.Selection.Unselect
                          For Each oshp In osldGroup.Shapes
                          If oshp.Type = msoPicture Then oshp.Select Replace:=False
                          Next oshp
                          With ActiveWindow.Selection.ShapeRange
                          If .Count > 1 Then
                          .Group
                          End If
                          End With
                          Next i

                          Dim ap As Presentation: Set ap = ActivePresentation
                          Dim sl As Slide
                          Dim shGroup As ShapeRange
                          For Each sl In ap.Slides
                          ActiveWindow.View.GotoSlide (sl.SlideIndex)
                          sl.Shapes.SelectAll
                          Set shGroup = ActiveWindow.Selection.ShapeRange
                          shGroup.Export filePath(sl.SlideIndex) & "" & fileName(sl.SlideIndex) & "_with logo" & ".jpg", ppShapeFormatJPG, , , ppScaleXY
                          Next

                          Set fd = Nothing
                          Dim v As Long
                          For v = 1 To Application.ActivePresentation.Slides.Count
                          ActivePresentation.Slides.Range(1).Delete
                          Next v

                          End Sub





                          share|improve this answer












                          For the curios or those with the same problem. Here's the final successful macro with what I learned from Ahmed's Answer.



                          I added image scaling since the output size was way smaller than the original.



                          Sub saveWithLogo()

                          Dim fd As FileDialog
                          Dim directory As String
                          Dim vrtSelectedItem As Variant
                          Dim osld As Slide
                          Dim oPic As Shape
                          Dim osldGroup As Slide
                          Dim oshp As Shape
                          Dim logoPic As Shape
                          Dim i As Integer
                          Dim num_pics As Integer
                          Dim fso As New FileSystemObject
                          Dim fileName As New Collection
                          Dim filePath As New Collection
                          Dim finalName As String

                          Set fd = Application.FileDialog(msoFileDialogFilePicker)
                          With fd 'Get pictures from file dialog, add logo to each picture
                          If .Show = -1 Then
                          For Each vrtSelectedItem In .SelectedItems
                          numPics = .SelectedItems.Count
                          fileName.Add fso.GetBaseName(vrtSelectedItem)
                          filePath.Add fso.GetParentFolderName(vrtSelectedItem)
                          Set osld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
                          Set oPic = osld.Shapes.AddPicture(vrtSelectedItem, msoFalse, msoTrue, 50, 50)
                          With oPic
                          .LockAspectRatio = msoTrue
                          .ScaleWidth 1.875, msoTrue
                          End With
                          logoWidth = 6.18 * 28.3
                          logoHeight = 1.4 * 28.3
                          Set logoPic = osld.Shapes.AddPicture("C:PicturesLogo Images" & "logo.png", lsoFalse, msoTrue, 100, 85, logoWidth, logoHeight)
                          With logoPic
                          .LockAspectRatio = msoTrue
                          .ScaleWidth 0.005 * oPic.Width, msoTrue
                          End With
                          Set oPic = Nothing
                          Set logoPic = Nothing
                          Next vrtSelectedItem
                          End If
                          End With

                          For i = 1 To numPics 'Groups pictures on slide
                          Set osldGroup = ActivePresentation.Slides(i)
                          ActivePresentation.Slides(i).Select
                          ActiveWindow.Selection.Unselect
                          For Each oshp In osldGroup.Shapes
                          If oshp.Type = msoPicture Then oshp.Select Replace:=False
                          Next oshp
                          With ActiveWindow.Selection.ShapeRange
                          If .Count > 1 Then
                          .Group
                          End If
                          End With
                          Next i

                          Dim ap As Presentation: Set ap = ActivePresentation
                          Dim sl As Slide
                          Dim shGroup As ShapeRange
                          For Each sl In ap.Slides
                          ActiveWindow.View.GotoSlide (sl.SlideIndex)
                          sl.Shapes.SelectAll
                          Set shGroup = ActiveWindow.Selection.ShapeRange
                          shGroup.Export filePath(sl.SlideIndex) & "" & fileName(sl.SlideIndex) & "_with logo" & ".jpg", ppShapeFormatJPG, , , ppScaleXY
                          Next

                          Set fd = Nothing
                          Dim v As Long
                          For v = 1 To Application.ActivePresentation.Slides.Count
                          ActivePresentation.Slides.Range(1).Delete
                          Next v

                          End Sub






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 13 '18 at 16:35









                          b.sauerb.sauer

                          526




                          526






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270866%2fhow-to-save-shape-groups-as-photo-to-filedialog-path-with-amended-name%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Florida Star v. B. J. F.

                              Error while running script in elastic search , gateway timeout

                              Adding quotations to stringified JSON object values