Excel VBA多范围打印预览

时间:2016-09-19 08:25:55

标签: excel vba excel-vba

嗨,这可能有点困难..是否有可能......

我想打印范围B:D&效靶 和B:D& V:AK ..我尝试使用以下代码......但只有B:D& E:T PrintPreview出现

    Columns("B:D").EntireColumn.Hidden = False
    Columns("E:T").EntireColumn.Hidden = False
    Columns("V:AK").EntireColumn.Hidden = False    
    Dim r1, r2, r3 As Range
    Set r1 = Range("B:D")
    Set r2 = Range("E:T")
    Set r3 = Range("V:AK")
    Dim p1, p2 As Range
    Set p1 = Range(r1, r2)
    Set p2 = Range(r1, r3)

    ActiveSheet.PageSetup.PaperSize = xlPaperA4
    ActiveSheet.PageSetup.Orientation = xlLandscape
    ActiveSheet.Range(p1, p2).PrintPreview

1 个答案:

答案 0 :(得分:0)

您在顶部有两次Columns("E:T").EntireColumn.Hidden = False次。是因为你的意思是第二个是Columns("V:AK").EntireColumn.Hidden = False吗?

此外,您可以在取消隐藏中使用您的范围:

Dim r1 As Range, r2 As Range, r3 As Range

Set r1 = Range("B:D")
Set r2 = Range("E:T")
Set r3 = Range("V:AK")

r1.EntireColumn.Hidden = False
r2.EntireColumn.Hidden = False
r3.EntireColumn.Hidden = False

ActiveSheet.PageSetup.PrintArea = r1.Address & "," & r2.Address & "," & r3.Address
ActiveSheet.PageSetup.PaperSize = xlPaperA4
ActiveSheet.PageSetup.Orientation = xlLandscape
ActiveSheet.VPageBreaks(1).Location = Range("U1")
ActiveSheet.PrintPreview