Hello everyone. I am trying to figure out the particulars for exporting sets of shapes (without surrounding whitespace) on a slide. Essentially, my working code is as follows:
[vba]
Public Sub CreateSlides()
Dim I As Integer
Dim ReferenceSlide As PowerPoint.Slide
Dim PowerPointSlide As PowerPoint.Slide
Dim PowerPointPicture As PowerPoint.Shape
Dim ContourLegend As PowerPoint.Shape
Dim ObjectLegend As PowerPoint.Shape
Dim LargestDimension As String
Dim NewFileName As String
Call GetPictureList 'Generates array of picture file paths
Set ReferenceSlide = ActivePresentation.Slides(1)
For I = 0 To UBound(PictureList)
Set PowerPointSlide = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, Layout:=ppLayoutBlank)
Set PowerPointPicture = PowerPointSlide.Shapes.AddPicture(FileName:=PictureList(I), LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=0, Top:=0)
'Doing stuff
'this
'that
'etc.
'Export slide as picture
NewFileName = RemoveExtension(PictureList(I))
'Method 1
PowerPointSlide.Export NewFileName & ".png", "png"
'Method 2
ActiveWindow.Selection.SlideRange(PowerPointSlide.SlideIndex - 1).Select
ActiveWindow.Panes(2).Activate
ActiveWindow.Selection.SlideRange(PowerPointSlide.SlideIndex - 1).Shapes.SelectAll
ActivePresentation.SaveAs _
FileName:=NewFileName, _
FileFormat:=ppSaveAsPNG, _
EmbedTrueTypeFonts:=msoFalse
Next I
End Sub
[/vba]
In a nutshell, the code gets a set of user selected files and iteratively, adds them to a new blank slide, does some moving around, and then exports the slide. The code works great while using method 1, however there is a bunch of extra white space surrounding the shapes and picture (as you would see on the PowerPoint slide itself). Method 2 is my VBA recreation of selecting a slide, doing a select all, and using right-click "Save as Picture." Manually performing method 2 gives me an image without the extra white space (just the bounds of the shape group). The VBA version of method 2 ends up exporting the existing presention for each iteration (each picture with white space).
Does anyone know how I can perform a "Save as Picture" programmatically in the loop without getting the extra white space?
Thanks for any help or direction you can give me.