要将打印区域自动调整为工作表内容,我使用以下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属性为空,所以我不能用它来检测条件。
答案 0 :(得分:0)
已解决:只需比较ActiveSheet.UsedRange范围的宽度和高度:
If ActiveSheet.UsedRange.Width > ActiveSheet.UsedRange.Height Then
.Orientation = xlLandscape
End If