我正在尝试将单个页面设置为横向,但是我尝试的每种方法都会更改整个文档,而不是我设置 PageSetup 的部分\段落。这是一个例子,第一页应该是纵向的,第二页应该是横向的:
Dim wrdApp As Word.Application
Dim wrdDoc As Word._Document
Public Sub test()
Dim wrdSelection As Word.Selection
Dim wrdDataDoc As Word._Document
Dim sText As String
wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
wrdDataDoc = wrdApp.Documents.Open("C:\Temp\Doc1.docx")
wrdDataDoc.PageSetup.Orientation = WdOrientation.wdOrientPortrait
Dim oPara1 As Paragraph
sText = "Test Report Title"
oPara1 = wrdDataDoc.Content.Paragraphs.Add
oPara1.Range.Text = sText
oPara1.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter
oPara1.Range.InsertParagraphAfter()
Dim para As Word.Paragraph = wrdDataDoc.Paragraphs.Add()
para.Range.InsertBreak()
wrdApp.Selection.GoTo(Word.WdGoToItem.wdGoToLine, Word.WdGoToDirection.wdGoToLast)
wrdDataDoc.Sections(1).PageSetup.Orientation = WdOrientation.wdOrientLandscape
wrdSelection = wrdApp.Selection()
wrdDataDoc.Tables.Add(wrdSelection.Range, NumRows:=9, NumColumns:=4)
With wrdDataDoc.Tables.Item(1)
'Code for table here
End With
End Sub