2017-02-03 72 views
0

我有一個查詢數據庫的Excel表格 - 它返回的行數波動。自動調整表格以適合屏幕

有誰知道如何自動調整表格的大小,當行數改變,以便整個表總是適合在屏幕上?

回答

1

聽起來好像你指的是縮放。所有積分Chip Pearson這個方便的子。

實例:call ZoomToRange(activesheet.cells(1,1).currentregion, true)

Sub ZoomToRange(ByVal ZoomThisRange As Range, _ 
    ByVal PreserveRows As Boolean) 
'http://www.cpearson.com/excel/zoom.htm 
Dim Wind As Window 

Set Wind = ActiveWindow 
' 
' Put the upper left cell of the range in the top-left of the screen. 
' 
Application.Goto ZoomThisRange(1, 1), True 

With ZoomThisRange 
    If PreserveRows = True Then 
     .Resize(.Rows.Count, 1).Select 
    Else 
     .Resize(1, .Columns.Count).Select 
    End If 
End With 

With Wind 
    .Zoom = True 
    .VisibleRange(1, 1).Select 
End With 

End Sub 
+0

WOW。感謝分享這個。 – eggwhites