首页 > 解决方案 > 为整个页面插入边框

问题描述

With Selection.Borders(wdBorderRight) 
 .LineStyle = wdLineStyleSingle 
 .LineWidth = wdLineWidth075pt 
End With
With Selection.Borders(wdBorderLeft) 
 .LineStyle = wdLineStyleSingle 
 .LineWidth = wdLineWidth075pt 
End With

我是 VBA 的新手,没有找到方法或误解了它们。我想为整个页面(左右)创建一个边框 上面的代码只为单行

标签: vbams-word

解决方案


以下代码(来自宏记录器)显示了您需要的属性和方法。除其他外,它表明您自己的代码缺少必要的 Sections 引用-您的代码所做的只是将边框应用于实际选择的内容-而不是基础Section。当然,根据您要实现的目标,您不太可能需要以下所有代码 - 或者您可能需要使用不同的参数。

Sub Demo()
  With Selection.Sections(1)
    With .Borders(wdBorderLeft)
      .LineStyle = wdLineStyleSingle
      .LineWidth = wdLineWidth050pt
      .Color = wdColorAutomatic
    End With
    With .Borders(wdBorderRight)
      .LineStyle = wdLineStyleSingle
      .LineWidth = wdLineWidth050pt
      .Color = wdColorAutomatic
    End With
    With .Borders(wdBorderTop)
      .LineStyle = wdLineStyleSingle
      .LineWidth = wdLineWidth050pt
      .Color = wdColorAutomatic
    End With
    With .Borders(wdBorderBottom)
      .LineStyle = wdLineStyleSingle
      .LineWidth = wdLineWidth050pt
      .Color = wdColorAutomatic
    End With
    With .Borders
      .DistanceFrom = wdBorderDistanceFromPageEdge
      .AlwaysInFront = True
      .SurroundHeader = True
      .SurroundFooter = True
      .JoinBorders = False
      .DistanceFromTop = 24
      .DistanceFromLeft = 24
      .DistanceFromBottom = 24
      .DistanceFromRight = 24
      .Shadow = False
      .EnableFirstPageInSection = True
      .EnableOtherPagesInSection = True
      .ApplyPageBordersToAllSections
    End With
  End With
End Sub

推荐阅读