2012-09-28 61 views
1

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

的代码如下:

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 

非常感谢您!

+0

请把相关的查询更多的代码。 – djadmin

+0

谢谢,我现在在 – user1706599

+0

之上发布了我的脚本的全部内容。其余代码是什么样的? –

回答

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 
+0

Steve,非常感谢,非常棒! – user1706599