vba - 为整个页面插入边框
问题描述
With Selection.Borders(wdBorderRight)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth075pt
End With
With Selection.Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth075pt
End With
我是 VBA 的新手,没有找到方法或误解了它们。我想为整个页面(左右)创建一个边框 上面的代码只为单行
解决方案
以下代码(来自宏记录器)显示了您需要的属性和方法。除其他外,它表明您自己的代码缺少必要的 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
推荐阅读
- terraform - Terrafrom:如何使用附加名称查询 AWS ACM 证书?
- sql - 我需要一些帮助来解决 SQL 查询,我需要列出要求至少一种产品但不要求牛奶的消费者的姓名
- html - 在没有滑块的面板上显示长文本
- python - 为什么我的 Flask 服务器在部署到 Docker 容器后无法连接?
- c# - 尝试更改 MainPage 但新页面上的 WebView 无法加载站点。但是当我在应用程序启动时将它设置为主页时它是成功的
- sql - 多连接选择
- android - Jetpack 的 BiometricPrompt (androidx.biometric.BiometricPrompt) 抛出 NullPointerException
- java - 如何回滚捕获异常的事务?
- html - 响应式轮播库
- javascript - 访问其他HTML页面时如何避免与当前socket.io连接断开