|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
代码如下。。。。
Sub SelectPrintArea()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim selectedRange As Range, rng As Range
' On Error Resume Next
Sheet1.Copy after:=Sheet1: ActiveSheet.Name = "临时"
Sheet1.Activate
Set selectedRange = Application.InputBox("请选择要打印的区域", "选择打印区域", Type:=8)
If Err.Number <> 0 Then
MsgBox "您未选择有效区域,操作取消。"
Exit Sub
End If
For Each rng In Sheet1.UsedRange
If Intersect(rng, selectedRange) Is Nothing Then
rng.Font.ColorIndex = 2
rng.Borders.ColorIndex = 2
rng.Interior.ColorIndex = 2
End If
Next
With ActiveSheet.PageSetup
.Zoom = False
.PrintArea = Sheet1.[a1].CurrentRegion.Address
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
ActiveSheet.PrintOut
Sheets("临时").UsedRange.Copy Sheet1.[a1]
Sheets("临时").Delete
Beep
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
|
|