设置打印区域,然后再打印。这种设置将会保存到EXCEL文件中。比如:
Worksheets("Sheet1").PageSetup.PrintArea
=
"$A$1:$C$5"
Worksheets("Sheet1").PrintOut
方法2:直接打印指定区域,而不修改打印区域设置。比如
Worksheets("Sheet1").Range("$A$1:$C$5").PrintOut
Sub pppp()For i = 1 To 31
With Sheets(i)
.Select
.PageSetup.PrintArea = ""
ActiveWindow.View = xlPageBreakPreview
t = .HPageBreaks(.Range("r2")).Location.Offset(-1, 5).Address '假设要打印前5列
.PageSetup.PrintArea = "A1:" &t
End With
Next i
End Sub
Sub ABC()Dim iCount As Integer
Dim MyPrintArea As String
For i = 300 To 1 Step -1
If Range("B" & i) <> "" Then
iCount = i
Exit For
End If
Next
MyPrintArea = "$A$1:$O$" & iCount
Range("$A$1:$O$" & iCount).Select
Selection.Columns.AutoFit
Range("A8").Select
ActiveSheet.PageSetup.PrintArea = MyPrintArea
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)