vba 使用excel宏在word中插入分页符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21120041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
inserting page break in word using excel macro
提问by user3194519
I am creating a macro that copies data from excel into word. I can't get the macro to insert a page break after I just copied the range of cells into word. I get the following error
我正在创建一个将数据从 excel 复制到 word 的宏。在我刚刚将单元格范围复制到 word 后,我无法让宏插入分页符。我收到以下错误
Object doesn't support this property or method.
对象不支持此属性或方法。
I am guessing this happens because the copied data in Word is still highlighted and I need to get a cursor at the bottom of the new copied date before I try to insert a page break.
我猜这是因为 Word 中复制的数据仍然突出显示,在尝试插入分页符之前,我需要在新复制日期的底部找到一个光标。
How do I do this?
我该怎么做呢?
This is a section of the code that is not working - actually the last line of the code but I thought I should show you right before as well:
这是一段不起作用的代码 - 实际上是代码的最后一行,但我想我也应该在此之前向您展示:
Range("A1:F25").Select
Selection.Copy
appWD.Documents.Add
appWD.Selection.PasteSpecial Link:=True, DataType:=wdPasteEnhancedMetafile
DoEvents
appWD.InsertBreak Type:=wdPageBreak
回答by Ben Black
Try this instead:
试试这个:
With appWD.Selection
.Collapse Direction:=0
.InsertBreak Type:=7
End With
来源:http: //msdn.microsoft.com/en-us/library/microsoft.office.interop.word.selection.insertbreak(v=office.14).aspx
http://www.utteraccess.com/forum/Error-9118-protect-Docu-t1123894.html
http://www.utteraccess.com/forum/Error-9118-protect-Docu-t1123894.html