AlexMason
07-20-2010, 07:26 AM
Right so my 3rd sticking point of the week! and its only tuesday! i wish they'd hire proper programmers here and not make the engineers do it.
anyway
im trying to copy a formatted and completed table from Excel, into word.
now i can open word, create a new document, set the page up with the right margins and paste the table in. however, i plan to have a For loop based on the number of tables to paste.
so what i need to do is once a table is pasted, i need to put in a section break to next page or a page break or something to start the cursor on a new page and then paste the 2nd table in. then again, a break of some sort so i can paste the 3rd table into page 3 and so on.
heres what i coded. It wont execute the InsertBreak command... im guessing because im trying to break the table and not the page. i dunno.
Public Sub wordGEN()
'in here, need code that opens a word document, new, and then generates a table? or opens a template table (might be easier) and then uses
'uses the public variables to operate on excel table, brining the data over to the word table.
Dim wrdApp As New Word.Application
Dim wrdDoc As Word.Document
Dim pageRNG As Range
Dim HP As Worksheet
Dim IP As Worksheet
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.ADD
With wrdDoc
.PageSetup.RightMargin = CentimetersToPoints(1.27)
.PageSetup.TopMargin = CentimetersToPoints(1.27)
.PageSetup.BottomMargin = CentimetersToPoints(1.27)
.PageSetup.LeftMargin = CentimetersToPoints(1.27)
End With
Set pageRNG = Sheets("HP").Range("B2:H35")
pageRNG.Copy
With wrdDoc
.Content.Paste
.InsertBreak Type:=wdPageBreak
End With
End Sub
what am i doing wrong?
(ignore the set PageRNG bit, what i plan to do is have the range set to that but then offset it by x each time through the loop when i get to that point. at the moment im just trying to get it to move onto a new page once its pasted a table)
anyway
im trying to copy a formatted and completed table from Excel, into word.
now i can open word, create a new document, set the page up with the right margins and paste the table in. however, i plan to have a For loop based on the number of tables to paste.
so what i need to do is once a table is pasted, i need to put in a section break to next page or a page break or something to start the cursor on a new page and then paste the 2nd table in. then again, a break of some sort so i can paste the 3rd table into page 3 and so on.
heres what i coded. It wont execute the InsertBreak command... im guessing because im trying to break the table and not the page. i dunno.
Public Sub wordGEN()
'in here, need code that opens a word document, new, and then generates a table? or opens a template table (might be easier) and then uses
'uses the public variables to operate on excel table, brining the data over to the word table.
Dim wrdApp As New Word.Application
Dim wrdDoc As Word.Document
Dim pageRNG As Range
Dim HP As Worksheet
Dim IP As Worksheet
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.ADD
With wrdDoc
.PageSetup.RightMargin = CentimetersToPoints(1.27)
.PageSetup.TopMargin = CentimetersToPoints(1.27)
.PageSetup.BottomMargin = CentimetersToPoints(1.27)
.PageSetup.LeftMargin = CentimetersToPoints(1.27)
End With
Set pageRNG = Sheets("HP").Range("B2:H35")
pageRNG.Copy
With wrdDoc
.Content.Paste
.InsertBreak Type:=wdPageBreak
End With
End Sub
what am i doing wrong?
(ignore the set PageRNG bit, what i plan to do is have the range set to that but then offset it by x each time through the loop when i get to that point. at the moment im just trying to get it to move onto a new page once its pasted a table)