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