|
本帖最后由 风哈哈 于 2019-9-15 17:23 编辑
纯小白一枚,在工作时遇到打印需要每行底下有横线的要求,根据教材的提示,输入以下代码,结果出现“编辑错误”,请大神们指教!
Sub AddGrid()
Dim tempSection As Double
Dim pgWidth As Double, pgHight As Double
Dim pgLeft As Double, pgTop As Double
Dim pgRight As Double, pgBottom As Double
Dim shapeDistance As Double, tempShape As Shape
Dim i As Long
Application.ScreenUpdating = False '关闭屏幕更新
For Each tempSection In ActiveDocument.Sections '在每节中循环
'在页眉页脚中循环
With tempSection.Headers(wdHeaderFooterPrimary)
With tempSection.PageSetup
pgWidth = .PageWidth '页宽
pgHight = .PageHeight '页高
pgLeft = .LeftMargin '左边距
pgRight = .RightMargin
pgTop = .TopMargin
pgBottom = .BottomMargin + 11 '11这个数字可能根据文档的不同而稍有变化
'每一行网格线的间距
shapeDistance = (pgHight - pgTop - pgBottom) / .LinesPage
End With
'在页眉处添加直线,产生类似于网络线的效果
For i = 1 To tempSection.PageSetup.LinesPage + 1
Set tempShape = .Shapes.AddLine(pgLeft, pgTop, pgWidth - pgRight, pgTop)
tempShape.WrapFormat.Type = wdWrapNone
'tempShape.Width =
Debug.Print shapeDistance
'每画一条直线后,纵向向下移一个间距
pgTop = pgTop + shapeDistance
Next
End With
Next
'开启屏幕更新
Application.ScreenUpdating = True
End Sub
|
|