首先,插入一行并将其隐藏在分页符之前。然后,您可以使用BeforePrint
工作簿上的事件来查找其中包含“查看下一页”文本的所有行,然后取消隐藏它们。
Sub Workbook_BeforePrint(cancel as Boolean)
Dim rngCell as Range
set rngCell = ActiveSheet.UsedRange.Find("See Next Page")
while not rngCell is Nothing
if not rngCell is Nothing then
rngCell.EntireRow.Hidden = false
end if
set rngCell = ActiveSheet.UsedRange.FindNext()
loop
End Sub
如果您需要去,这会让您有所收获,但是,它会让您容易受到以下事实的影响:没有AfterPrint
. 因此,您可以执行以下操作:
Sub Workbook_BeforePrint(cancel as Boolean)
Application.EnableEvents = false
'Unhide rows here
if cancel then
Workbook.PrintPreview()
else
Workbook.PrintOut()
end if
'Rehide rows here
Application.EnableEvents = True
End Sub
请注意,这cancel
基本上会告诉您它是打印预览还是实际打印命令。我认为它非常友好。