我在PowerPoint VBA中创建一个宏以从当前幻灯片导出图像。导出图像将是宽度超过250个单位的第一个图像。图像存储为Shape
,所以我做了一个For Each ... Next
循环来做到这一点。代码工作正常。如何使用vba在PowerPoint中调整导出图像大小?
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
问题
导出的图像pic_VBA.jpg
远小于它在PowerPoint中所示。 我想要图片的原始尺寸。由VBA pic_VBA.jpg
导出的图像尺寸为331 x 413。如果我使用另存为图片...手动导出图像,导出图像pic_SaveAs.jpg
的尺寸为692 x 862,这是原始尺寸。
pic_VBA.jpg
尺寸:331 X 413pic_SaveAs.jpg
尺寸:692 X 862(原始大小)
我测试
s.Export myTempPath, ppShapeFormatJPG, s.Width, s.Height, ppScaleXY
它不工作。出口图像的尺寸为150×413
问题
那么,如何在PowerPoint中使用VBA调整出口图像大小?
相关infomations
请问我可以在我的代码中使用你的函数吗?我以前从不使用'Type'。我应该像'Dim myType As ypPictureScale'一样声明使用某种东西吗? –
类型声明必须放入代码模块的声明部分(首先是Sub和Function过程)。 –
嗨@JamieG,我试过了。你可能忘记在第27行和第28行添加前缀“yp”?在第27行中,它应该是'PictureScale。代替ypScaleH'。除了这个问题,你的代码完美地工作。然而,它并没有解决我的问题,因为它导出的图像大小与我使用默认设置's.Export myTempPath,ppShapeFormatJPG'时的大小相同。我无法接受它,但我赞成你的答案。我现在不再处理这个问题(我的同事不再需要它了),但感谢您的帮助! –