【问题标题】:Excel VBA: How to detect that the printed width is greater than the printed heightExcel VBA:如何检测打印宽度大于打印高度
【发布时间】: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


【解决方案1】:

已解决:只比较ActiveSheet.UsedRange范围的宽高:

If ActiveSheet.UsedRange.Width > ActiveSheet.UsedRange.Height Then
    .Orientation = xlLandscape
End If

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-28
    • 1970-01-01
    • 1970-01-01
    • 2020-03-19
    • 1970-01-01
    • 2021-03-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多