Exporting data from excel to work and adding a page break

JackWhitman

New Member
Joined
Jul 21, 2015
Messages
1
Hi,

I've written a macro that exports my data from excel into a word document through bookmarks. This works relatively well, however I would like to be able to add a page break after certain tables are added, but I'm new to VBA and can't figure it out. I would like to add the page break in the If statement, when It will check if a cell is empty or not, then paste the table, page break, next if statement and so on.

Any help is greatly appreciated

Code:
Sub CopyToWord()

Dim objWord As Object
Dim ws As Worksheet
Dim wdApp  As Object


    Set ws = ThisWorkbook.Sheets("Summary")
    Set objWord = CreateObject("Word.Application")
    
         Application.ScreenUpdating = False
         Application.EnableEvents = False


    objWord.Visible = True


    objWord.Documents.Open "H:\Customer Letters\MASTER_TEMPLATE.docm" 


    With objWord.ActiveDocument

    ' Title Page
        .Bookmarks("AccountNo1").Range.Text = ws.Range("B3").Value
        .Bookmarks("CustomerName1").Range.Text = ws.Range("B1").Value

....code....

        If Len(Range("A5").Value) <> 0 Then
            Range("A19:G50").Select
                Selection.Copy
                    .Bookmarks("Model1").Range.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=True
                    'THIS IS WHERE I WOULD LIKE TO ADD A PAGE BREAK
            Else
        End If
        
    End With
      
    ' Clear the clipboard
    Application.CutCopyMode = False
    
    'This macro applies some formatting to charts and tables that are pasted
    objWord.Run "TestMacro1"


    Set objWord = Nothing
      
    Application.ScreenUpdating = True
    Application.EnableEvents = True


End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,223,228
Messages
6,170,874
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top