1

我在 VB 中的 powerpoint 中工作,我正在尝试编写一个简单的宏,它只在我当前正在编辑的幻灯片上调整任何图像的大小和居中。我已经成功编写了图像大小和居中的代码,但它只适用于我演示文稿的第一张幻灯片,即使我目前正在查看和编辑另一张幻灯片。如何将代码应用于我正在查看的幻灯片?

代码如下:

Dim shp As Shape
Dim sld as Slide

Dim x As Integer
Dim y As Integer

With ActivePresentation.PageSetup
x = .SlideWidth / 2
y = .SlideHeight / 2
End With


For Each sld In ActiveWindow.Selection.SlideRange
For Each shp In sld.Shapes

If shp.Type = msoPicture Then
shp.Height = y * 2 

shp.Width = x * 2

shp.Left = x - (shp.Width / 2)
shp.Top = y - (shp.Height / 2)
End If

Next
Next


End Sub

非常感谢!

4

1 回答 1

0

单步执行您的代码,看看这行之后会发生什么:

如果 shp.Type = msoPicture 则

在幻灯片 1 之后执行以下行吗?我猜你的形状是 msoPlaceholder 而不是 msoPicture,所以你的大小调整代码永远不会触发。

试试这个:

Dim shp As Shape
Dim sld As Slide

Dim x As Integer
Dim y As Integer

With ActivePresentation.PageSetup
x = .SlideWidth / 2
y = .SlideHeight / 2
End With


For Each sld In ActiveWindow.Selection.SlideRange
For Each shp In sld.Shapes

If shp.Type = msoPicture Then
shp.Height = y * 2

shp.Width = x * 2

shp.Left = x - (shp.Width / 2)
shp.Top = y - (shp.Height / 2)
End If

If shp.Type = msoPlaceholder Then
    If shp.PlaceholderFormat.ContainedType = msoPicture Then
        shp.Height = y * 2
        shp.Width = x * 2
        shp.Left = x - (shp.Width / 2)
        shp.Top = y - (shp.Height / 2)
    End If
End If

Next
Next
于 2012-09-28T21:48:08.590 回答