Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting a word table on a new page using MS Access VBA

Status
Not open for further replies.

KM88

Programmer
Sep 29, 2019
2
US
Hi all,

I'm creating a bunch of letters in one giant word document and the letters are comprised of tables. When a new letter is required I'm trying to get the first table for the letter to show up on a new page in word as it's required to be a new letter, at the moment it's just pasting the first table right below the letter before it. I was hoping there was a trick with this code that will push the table I want to the next newest page? I've tried some stuff but I think it's the range that is stopping it from happening, any suggestions???

Thanks!

Sub CopyTableToEnd(wd As Word.Document, oWordTbl As Object, w As Word.Application)

Dim rngTableTarget As Word.Range

Set rngTableTarget = wd.Content

rngTableTarget.Start = wd.Content.End

rngTableTarget.FormattedText = oWordTbl.Range.FormattedText

End Sub
 
Answer is here for anyone wondering:

Sub CopyTableToEnd(wd As Word.Document, oWordTbl As Object, w As Word.Application)

Dim rngTableTarget As Word.Range

Set rngTableTarget = wd.Content

rngTableTarget.Start = wd.Content.End

rngTableTarget.InsertBreak Type:=wdPageBreak

rngTableTarget.FormattedText = oWordTbl.Range.FormattedText

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top