当我需要做你所说的事情时,我会做的是。
在代码编辑器(VBA)中使用函数:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
来隐藏行或列,进行打印,然后取消隐藏。
示例:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Name = "Sheet1" Then
Cancel = True
Application.EnableEvents = False
Application.ScreenUpdating = False
With ActiveSheet
.Rows("10:15").EntireRow.Hidden = True
.PrintOut
.Rows("10:15").EntireRow.Hidden = False
End With
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub
或者改变相应的部分来隐藏列(本例隐藏B列和D列):
With ActiveSheet
.Range("B1,D1").EntireColumn.Hidden = True
.PrintOut
.Range("B1,D1").EntireColumn.Hidden = False
End With
或者隐藏所有的行,A列的单元格为空白:
With ActiveSheet
On Error Resume Next
.Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
.PrintOut
.Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = False
On Error GoTo 0
End With
链接。