我正在尝试使用Word和VBA,但我有一点问题:
我目前有3个页面,所有页面都有2个列,但我想要第一页,只有第一页,有1列。
有人知道如何解决这个问题吗?
我的代码:
Set appWord = CreateObject("Word.Application")
appWord.DisplayAlerts = False
Set wordDoc = appWord.Documents.Open(Application.GetOpenFilename("Word-Dateien (*.doc;*.docx;),*.doc;*.docx"))
wordDoc.Activate
wordDoc.Sections(1).PageSetup.TextColumns.SetCount NumColumns:=2
这是我目前停止的地方,因为我不知道如何做对。 致以最诚挚的问候,并非常感谢您的回答
答案 0 :(得分:1)
假设您的文档中有段落或由您的代码创建。例如您知道您的第一页在文档的第4段后结束。
Sub reportCreation()
Dim myRange As Range
'Place where your report is generated - include wordApp activation etc. according to your needs.
'Define the range after which you want to add your page break section - here paragraph 4
Set myRange = ActiveDocument.Paragraphs(4).Range
'Add the Next Page section Break
ActiveDocument.Sections.Add Range:=myRange, _
Start:=wdSectionContinuous
'Now your report is separated in two sections: 1st section-> 1st page, 2nd section->rest of the report
wordDoc.Sections(2).PageSetup.TextColumns.SetCount NumColumns:=2
End Sub