2016-01-20 56 views
0

我想用Word和VBA的东西,但我有一个小问题: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

我想当你说网站你的意思是在你的Word文档中的页面?或者是那些部分? – Genie

+0

你的权利,我的意思是页面:)对不起 – ndslr

+0

这是一次性的事情,还是你想要将它整合到其他代码中?自动创建定期报告? – Genie

回答

1

假设您在文档中有段落或由您的代码创建。例如你知道你的第一页在文档的第四段之后结束。

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 
+0

工作,但现在我有问题,它添加一个空白页,然后我所有的网页都有2列:/ – ndslr

+1

我已经在'Sections.Add'方法中添加'开始'参数。默认值是产生下一页分节符,这应该使其连续。让我知道这是否适合你。我怀疑你在第一页上填写了整个页面,不允许分节符在同一页面上共存。 – Genie

+0

嘿,是的,解决了空白页的问题,但即时通讯仍然试图弄清为什么第一页也变得格式化:( – ndslr

相关问题