I'm creating a macro in PowerPoint VBA to export an image from the current slide. The export image will be the first image having a width larder than 250 units. The image is stored as a Shape
, so I do a For Each ... Next
loop to do it. The code works fine.
Function FindAndSavePicture() As String
'
' Find the target picture at the active windows
'
'
Dim myTempPath As String
myTempPath = "C:\Users\" & Environ$("USERNAME") _
& "\AppData\Local\Microsoft\Windows\pic_VBA.jpg"
With ActiveWindow.Selection.SlideRange
For Each s In .Shapes
Debug.Print s.Name
If s.Type = msoPicture And s.Width > 250 Then
' Show scale
Debug.Print "s.Width=" & s.Width ' s.Width=323,3931
Debug.Print "s.Height=" & s.Height ' s.Height=405
' Save pic in file system
s.Export myTempPath, ppShapeFormatJPG
' assign the return value for this function
FindAndSavePicture = myTempPath
Exit For
End If
Next
End With
End Function
Problem
The exported image pic_VBA.jpg
is much smaller than it is shown in the PowerPoint. I want the original size of the picture. This exported image by VBA pic_VBA.jpg
has 331 x 413 in dimensions. And if I export the image manually using Save As Picture..., the exported image pic_SaveAs.jpg
has 692 x 862 in dimensions, which is the original size.
pic_VBA.jpg
dimensions : 331 x 413pic_SaveAs.jpg
dimensions : 692 x 862 (original size)
What I've tested
s.Export myTempPath, ppShapeFormatJPG, s.Width, s.Height, ppScaleXY
It doesn't work. The export image's dimensions are 150 x 413
Question
So, how to adjust export image size in PowerPoint using vba ?
Related infomations