自作ツール&スクリプト

【PowerPoint】画像を置換するマクロ

powerpoint-replace-picture-macro

パワポの画像の置換マクロを調べてみたものの、あまり良い方法が見つからず。

出来なくはないので、一応メモ。

画像置換のマクロ

Sub 画像置換()
Dim Pres As Presentation
Dim Sld As Slide
Dim shp As Shape
Dim l As Single
Dim t As Single
Dim h As Single
Dim w As Single
Dim strName As String
'画像のパス
Dim A As Variant
A = Array("C:\Users\namae\Desktop.png", "C:\Users\namae\Desktop.png", "C:\Users\namae\Desktop.png")
Dim idx As Integer
For Each Sld In ActivePresentation.Slides
For Each shp In Sld.Shapes
If shp.Type = msoPicture Then
l = shp.Left
t = shp.Top
h = shp.Height
w = shp.Width
strName = shp.Name
shp.Delete
Set shp = Sld.Shapes.AddPicture(A(idx), msoFalse, msoCTrue, l, t, w, h)
idx = idx + 1
If idx > UBound(A) Then idx = 0
shp.Name = strName
End If
Next shp
Next Sld
End Sub

参考

Replacing (changing) the pictures in PowerPoint presentation

[box04 title=”あわせて読みたい”]PowerPointに関する記事まとめ13選![/box04]

すいみん

パワポに関する記事をすべて掲載!