1

私はパワーポイントで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

どうもありがとうございました!

4

1 に答える 1

0

コードをステップ実行して、次の行の後に何が起こるかを確認します。

shp.Type = msoPicture の場合

次の行はスライド 1 の後に実行されますか? msoPicture ではなく msoPlaceholder 型の形状を持っていると推測しているため、サイズ変更コードがトリガーされることはありません。

代わりにこれを試してください:

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 に答える