Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inserting page break in word using excel macro

Tags:

excel

vba

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

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.

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
like image 564
user3194519 Avatar asked Feb 20 '26 02:02

user3194519


1 Answers

Try this instead:

With appWD.Selection
    .Collapse Direction:=0
    .InsertBreak Type:=7
End With

Source: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.selection.insertbreak(v=office.14).aspx

http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.selection.collapse(v=office.14).aspx

http://www.utteraccess.com/forum/Error-9118-protect-Docu-t1123894.html

like image 91
Ben Black Avatar answered Feb 21 '26 17:02

Ben Black