Word宏-设置所选页面的方向

问题描述 投票:0回答:1

我正在尝试创建一个宏,用户可以在其中选择文档中的表格并将其所在的特定页面的方向切换为横向。我已经尝试了录制动作和自己编写宏,但是似乎都无法正常工作。这与我所获得的内容非常接近,但是它使表格所在的页面以及之前的所有内容都可以显示。

Sub TableLandscape()
'
' TableLandscape Macro
'
'
    'Selection.Collapse Direction:=wdCollapseEnd
    'Selection.InsertBreak Type:=wdSectionBreakContinuous
    'ActiveDocument.Range(Start:=Selection.Start, End:=Selection.Start).Collapse Direction:=wdCollapseStart

    'Selection.InsertBreak _
         Type:=wdSectionBreakNextPage
    Selection.Start = Selection.Start + 1

    ActiveDocument.Range(Start:=Selection.End, End:=Selection.End).InsertBreak _
         Type:=wdSectionBreakNextPage

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

    'ActiveDocument.Range(Start:=Selection.End, End:=Selection.End).InsertBreak _
         'Type:=wdSectionBreakNextPage

End Sub
vba ms-word orientation
1个回答
0
投票

这里的操作方法:

Sub RotatePage()
    Dim TableRange As Range, TableStart As Range, TableEnd As Range
    Set TableRange = Selection.Tables(1).Range
    Set TableStart = TableRange.Duplicate
    With TableStart
        .SetRange Start:=TableStart.Start - 1, End:=TableStart.End
        .Collapse Direction:=wdCollapseStart
        .InsertBreak Type:=wdSectionBreakNextPage
    End With
    Set TableEnd = TableRange.Duplicate
    With TableEnd
        .SetRange Start:=TableEnd.Start, End:=TableEnd.End + 1
        .Collapse Direction:=wdCollapseEnd
        .InsertBreak Type:=wdSectionBreakNextPage
    End With
    TableRange.PageSetup.Orientation = wdOrientLandscape
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.