我在PPT中有一个Excel表,它动态地填充了来自另一个工作表的数据。第1行至第7行和第30行至36行的行高是固定的(ppt的页眉和页脚)。在从第8行到第26行的范围内,行在空时是隐藏的(我在一些行中输入了白色的"X“以保持它们的显示)。
在导出PPT模板时,我需要获得第2行到第36行的总高度为721 it,以适应我的PPT模板。
是否有可能动态调整“白色”行的行高(例如,第29行),以便为定义的范围(第2行至第36行)总共调整721 36?
发布于 2016-06-14 10:09:34
你可以这样做:
Option Explicit
Sub main()
Dim extraRowHeight As Double, totalRowsHeight As Double
Dim myRowsRange As Range
Const maxRowHeight As Double = 409 '<--| maximum allowed row height
totalRowsHeight = 721# '<--| set the total rows height you need for the range you are to specifiy right below
With Worksheets("MyTableSheet") '<--| change "MyTableSheet" with your actual sheet name
extraRowHeight = totalRowsHeight - .Rows("2:36").Height '<--| calculate the extra height needed for the wanted rows range
With .Rows(29) '<--| consider the "reservoir" row
If .RowHeight + extraRowHeight <= maxRowHeight Then '<--| if needed extra height leads to an allowable resulting "reservoir" row height ...
.RowHeight = .RowHeight + extraRowHeight '<--| ... then adjust "reservoir" row height
Else
.RowHeight = maxRowHeight '<--| ... otherwise adjust "reservoir" row to maximum allowable height ...
MsgBox "you still need to resize some other rows height for " & totalRowsHeight - .Rows("2:36").Height & " pts more" '<--|... and inform how much there still is to go
End If
End With
End With
End Sub
https://stackoverflow.com/questions/37807374
复制相似问题