|
可试试如下代码:- Sub test()
- '假设是普通表格,没有合并单元格
- Dim i As Integer '页数计数
- Dim c As Integer '每页数据行数
- Dim sum As Single
- Dim myTextframe As Shape
- Dim aCell As Cell
-
- Application.ScreenUpdating = False
- For i = 1 To ActiveDocument.ComputeStatistics(wdStatisticPages)
- With Selection
- .GoTo wdGoToPage, wdGoToAbsolute, i
- With ActiveDocument.PageSetup '设置文本框位置与大小
- Set myTextframe = ActiveDocument.Shapes.AddShape(msoShapeRectangle, _
- .PageWidth / 2 - 100, .PageHeight - .BottomMargin - 20, 160, 16)
- End With
- With .Tables(1)
- For Each aCell In .Columns(9).Cells
- If aCell.Range.Information(wdActiveEndPageNumber) = i Then
- c = c + 1
- sum = sum + Val(Replace(aCell.Range.Text, ",", ""))
- End If
- Next
- Stop
- End With
- With myTextframe
- .Fill.Visible = msoFalse
- .Line.Visible = msoFalse
- With .TextFrame
- .TextRange.Text = "本页" & IIf(i = 1, c - 1, c) & "行,共" & Format(sum, "standard") & "元"
- .TextRange.Font.Bold = True
- .TextRange.ParagraphFormat.Alignment = wdAlignParagraphCenter
- .MarginBottom = 0
- .MarginLeft = 0
- .MarginRight = 0
- .MarginTop = 0
- End With
- End With
- End With
- c = 0
- sum = 0
- Next
- Application.ScreenUpdating = True
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|