如何用vba设置word文档的页边距?

要在vba中设置word问的页边距,可以通过PageSetup对象设置。

代码如下所示:

Sub exceloffice()
    '作者QQ:1722187970,微信:xycgenius,微信公众号exceloffice
    Dim oDoc As Document
    Set oDoc = Word.ActiveDocument
    Dim oT As Table
    Dim oRow As Row
    Dim oColumn As Column
    With oDoc
        Dim oPS As PageSetup
        Set oPS = .PageSetup
        With oPS
            '左边距
            .LeftMargin = Word.CentimetersToPoints(2)
            '上边距
            .TopMargin = Word.CentimetersToPoints(2)
            '右边距
            .RightMargin = Word.CentimetersToPoints(1)
            '下边距
            .BottomMargin = Word.CentimetersToPoints(3)
        End With
    End With
End Sub

 

       

发表评论