2012-09-28 48 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