2011-03-16 120 views

回答

2

我會結合一個動態調整大小命名範圍與VBA方法。

首先創建一個名爲範圍,MyNamedRange:(假設你的表起始於$ A $ 1和表有頭)

=OFFSET(A1,0,0,COUNTA(A:A)-1,COUNTA(1:1)) 

然後,只需執行一行VBA的:

ActiveSheet.PageSetup.PrintArea = "MyNamedRange" 
0

如果您想要始終打印整個工作表,您實際上只需清除打印區域即可,它將默認爲填充數據的工作表的數量。如果你不想隱藏一些列,wtfsven的答案是完美的。

1

只要使用這個簡單的代碼:

Private Sub prnt() 
On Error Resume Next 

    Cells(1, 1).Select 
    With ActiveSheet.PageSetup 
    .PrintArea = Range(ActiveCell, ActiveCell.SpecialCells(xlCellTypeLastCell)).Select.Address 
    .Orientation = xlLandscape 
    .LeftHeader = "&p/&N" 
    .LeftFooter = ActiveWorkbook.FullName 'to show address 
    .PrintTitleRows = "$1:$5" 'repeat at top 
    .Zoom = False 
    .Orientation = xlLandscape 
    .FitToPagesWide = 1 'to print in 01 page 
    .FitToPagesTall = False 'to print in 01 page 
    End With 
End Sub 
0

我想這是一個很遲了迴應... 上述解決方案並沒有爲我在Excel 2007中工作,所以我用

begin_column = 1 
end_column = 5 

begin_row = 1 
end_row = 30 

'converting the numbers to uppercase letters 
temp_begin_column = Chr(first_column + 64) 
temp_end_column = Chr(second_column + 64) 

ActiveSheet.PageSetup.PrintArea = "$" & temp_begin_column & "$" & begin_row & ":$" & temp_end_column & "$" & end_row 

這可能看起來像一個複雜的解決方案,但它唯一可靠地爲我工作

0

我試過這個d它爲我工作。

StartColumn="A" 
StartRow=1 
EndColumn="B" 
EndRow=10 

ActiveSheet.PageSetup.PrintArea = StartColumn & StartRow & ":" & EndColumn & EndRow 
ActiveSheet.PageSetup.PrintArea = "A1:B10" 

Or 
ActiveSheet.PageSetup.PrintArea = "$" & StartColumn & "$" & StartRow & ":" & "$" & EndColumn & "$" & EndRow 
ActiveSheet.PageSetup.PrintArea = "$A$1:$B$10"