|
<p>技术不行!只能先在每页欲打印的行数后插入分页符!然后绘制两个窗体,一个是插入合计,一个是删除合计。</p><p>插入合计的窗体编程为:</p><p>Sub 插入合计()<br/> Dim iSubCol As Integer, rSubArea As Range<br/> Dim hb As HPageBreak</p><p> ActiveWindow.View = xlPageBreakPreview ' 进入 分页浏览 模式, 以便 EXCEL 正确计页<br/> Set r1stSubCell = Range("A8") ' 本例名单从 A8 单元格开始<br/> iSubCol = 25 ' 本例合计项共有25列</p><p> <br/> ActiveSheet.HPageBreaks.Add Before:=r1stSubCell.End(xlDown).Offset(1, 0)</p><p> ' 测试每一个分页符,<br/> ' 如果是自动分页符, 则在其上一行插入一小计行, 而本行纳入下一页<br/> ' 否则, 在本行插入一小计行<br/> For Each hb In ActiveSheet.HPageBreaks<br/> Set rCurrentCell = hb.Location<br/> rCurrentCell.Select ' 看看先</p><p> If hb.Type = xlPageBreakAutomatic Then Set rCurrentCell = rCurrentCell.Offset(-1, 0)</p><p> rCurrentCell.EntireRow.Insert<br/> Set rCurrentCell = rCurrentCell.Offset(-1, 0)</p><p> ' 添加分页合计内容<br/> With rCurrentCell<br/> .Value = "合计"<br/> .Font.Bold = True</p><p> Set rSubArea = .Offset(0, 1).Resize(1, iSubCol) ' 需要填充分页合计公式的区域<br/> <br/> ' 使用 SUBTOTAL 公式的好处是方便扩展, 且不会对已计算区域重复计算(如果可能发生这种情况的话)<br/> rSubArea.Formula = "=SUBTOTAL(9," & r1stSubCell.Offset(0, 1).Address(1, 0) & ":" & .Offset(-1, 1).Address(1, 0) & ")"</p><p> Set r1stSubCell = .Offset(1, 0)<br/> End With<br/> Next</p><p> ActiveWindow.View = xlNormalView<br/>End Sub</p><p>删除合计的窗体编程为:</p><p>Sub 删除原有的分页合计行()<br/> Set r1stSubCell = Range("A8") ' 本例名单从 A8单元格开始<br/> For Each rCurrentCell In Range(r1stSubCell, r1stSubCell.End(xlDown))<br/> If rCurrentCell = "合计" Then rCurrentCell.EntireRow.Delete<br/> Next<br/>End Sub<br/></p><p>这不是本人写的编程,偶尔查资料获得的!</p>[em04] |
|