AlexMason
07-21-2010, 07:24 AM
Private 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 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
Dim bmkNO As String
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")
For page = 1 To j
pageRNG.Copy
wrdDoc.Paragraphs(wrdDoc.Paragraphs.Count).Range.InsertParagraphAfter
wrdDoc.Paragraphs(wrdDoc.Paragraphs.Count).Range.Paste
Application.CutCopyMode = False
wrdDoc.Paragraphs(wrdDoc.Paragraphs.Count).Range.InsertParagraphAfter
With wrdDoc.Paragraphs(wrdDoc.Paragraphs.Count).Range
.InsertParagraphBefore
.Collapse Direction:=wdCollapseEnd
.InsertBreak Type:=wdPageBreak
End With
Next page
End Sub
j is a public variable by the way, as is page so dont worry that they arent defined up top.
anyway, the code gets to the line:
wrdDoc.Paragraphs(wrdDoc.Paragraphs.Count).Range.Paste
performs that paste and then simply stops....infact it stops and my user input form used to set all this off suddenly reappears infront of me like im just starting from the beginning. except i havent called it!
im actually stumped now, i have no idea whats going on.:banghead:
anyone got any ideas?
'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 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
Dim bmkNO As String
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")
For page = 1 To j
pageRNG.Copy
wrdDoc.Paragraphs(wrdDoc.Paragraphs.Count).Range.InsertParagraphAfter
wrdDoc.Paragraphs(wrdDoc.Paragraphs.Count).Range.Paste
Application.CutCopyMode = False
wrdDoc.Paragraphs(wrdDoc.Paragraphs.Count).Range.InsertParagraphAfter
With wrdDoc.Paragraphs(wrdDoc.Paragraphs.Count).Range
.InsertParagraphBefore
.Collapse Direction:=wdCollapseEnd
.InsertBreak Type:=wdPageBreak
End With
Next page
End Sub
j is a public variable by the way, as is page so dont worry that they arent defined up top.
anyway, the code gets to the line:
wrdDoc.Paragraphs(wrdDoc.Paragraphs.Count).Range.Paste
performs that paste and then simply stops....infact it stops and my user input form used to set all this off suddenly reappears infront of me like im just starting from the beginning. except i havent called it!
im actually stumped now, i have no idea whats going on.:banghead:
anyone got any ideas?