blog

【パワポVBA】全スライド・全テキストの余白を0にする

パワーポイントのテキストボックスの余白をマクロですべて「0」にする方法です。

余白を0にする例

スライドは2つあり、それぞれテキストボックスに文字が入力されています。

スライド

余白設定の画面です。

余白

この余白をすべて「0」にします。

スライド

余白をすべて「0」にした状態です。

余白設定

サンプルコード

Sub sumple()
    Dim sh As Shape
    Dim sld As Slide
    
    For Each sld In ActivePresentation.Slides
        For Each sh In sld.Shapes
            If sh.HasTextFrame Then
               With sh.TextFrame
                    .MarginLeft = 0
                    .MarginRight = 0
                    .MarginTop = 0
                    .MarginBottom = 0
                    .AutoSize = ppAutoSizeShapeToFitText
                    .WordWrap = msoFalse
                 End With
             End If
        Next
    Next
End Sub

-blog