Word Vba 设置文档方向的输入框 - IF with OR

Word Vba Input Box to set Document Orientation - IF with OR

在我的宏中,我想提示页面方向 -- P 或 p 表示纵向,L 或 l 表示横向。

这是我开发的。它有效 - 但想知道是否有 better/more 有效的方法来开发 "OR" 的 If 语句 --- 我是否必须使用 "nested" If??

    Dim i As Integer
    Dim oTbl As Table
    Dim rng As Range
    Dim Orientation As String

  With Selection.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = InchesToPoints(1)
        .BottomMargin = InchesToPoints(1)
        .LeftMargin = InchesToPoints(0.4)
        .RightMargin = InchesToPoints(0.4)
        .Gutter = InchesToPoints(0)
        .HeaderDistance = InchesToPoints(0.5)
        .FooterDistance = InchesToPoints(0.6)
        .PageWidth = InchesToPoints(8.5)
        .PageHeight = InchesToPoints(11)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .BookFoldPrinting = False
        .BookFoldRevPrinting = False
        .BookFoldPrintingSheets = 1
        .GutterPos = wdGutterPosLeft
    End With


' set Orientation


    Orientation = InputBox(Prompt:="Enter P for Portriait, L for Landscape")

    If Orientation = "L" Then
        With Selection.PageSetup
              .Orientation = wdOrientLandscape
        End With
    ElseIf Orientation = "l" Then
        With Selection.PageSetup
              .Orientation = wdOrientLandscape
        End With
    Else
        With Selection.PageSetup
              .Orientation = wdOrientPortrait
        End With
    End If

我不确定是否有更好(更有效)的方法来开发 MS Word 页面方向...我不会使用 InputBox,但如果你想使用它,我会做一些事情像这样:

AskAgain:
    Orientation = InputBox(Prompt:="Enter P for Portriait, L for Landscape")

    Select Case UCase(Orientation) 
         Case "L"
            Selection.PageSetup.Orientation = wdOrientLandscape
         Case "P"
            Selection.PageSetup.Orientation = wdOrientPortrait
         Case Else
            GoTo AskAgain
    End Select

老实说...将决定权留给用户,不要阻止用户通过 VBA 代码设置页面方向,而是调用打印预览 window。这是最好的方法 - 在我看来。