【发布时间】:2014-07-14 09:18:38
【问题描述】:
为了使打印区域自动适应工作表内容,我使用了以下 Excel 2010 VBA 代码:
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
Application.PrintCommunication = True
这行得通。现在另外我想检测打印的宽度是否大于打印的高度,然后改为横向打印。像这样的:
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
if .PrintedWidth > .PrintedHeight then ' how to detect it?
.Orientation = xlLandscape
end if
End With
Application.PrintCommunication = True
如何检测打印的宽度是否大于打印的高度?
我看到自动拟合后PrintArea属性是空的,所以我不能用它来检测条件。
【问题讨论】:
-
已解决:只比较ActiveSheet.UsedRange范围的宽高:If ActiveSheet.UsedRange.Width > ActiveSheet.UsedRange.Height Then .Orientation = xlLandscape End If跨度>
标签: excel vba printing width area