jwise
06-06-2012, 02:43 PM
I developed an Excel macro a few years ago which used Word 2003 to print a summary sheet for each data row in Excel. This summary sheet was a Word template which was printed then deleted. The loop acquired the template again until the rows were exhausted.
This logic works fine for a limited number of rows, but creates havoc with large numbers of rows. I decided to modify this code to produce a single Word file which I could "send" to Adobe to create a PDF where I could limit the number of pages I printed at one session.
When I do this, the document no longer formats correctly. If you compare the two pages side by side, the new version uses larger page margins (indentation is increased) causing the document to overflow its one page per row design. Both macros use the exact same template.
Here are code snippets:
' Original version
Set wrdApp = CreateObject("Word.Application")
For i = 3, lastRow
Set wrdDoc = wrdApp.Documents.Open(Filename:=C:\recap.dot")
' Process bookmarks
wrdApp.Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
Collate:=True, Background:=False, PrintToFile:=False, PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
Set wrdDoc = Nothing
Set rngDoc = Nothing
wrdApp.ActiveDocument.Close SaveChanges:=False
Next i
'================New Snippet=========
Set wrdApp = CreateObject("Word.Application")
wrdApp.Documents.Add
For i = 3, lastRow
rngDoc.InsertFile Filename:="C:\recap.dot"
'Do bookmark processing
rngDoc.InsertBreak Type:=wdPageBreak
next i
wrdApp.Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
Collate:=True, Background:=False, PrintToFile:=False, PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
Set rngDoc = Nothing
Set wrdDoc = Nothing
wrdApp.Quit SaveChanges:=False
Set wrdApp = Nothing
The fault again is that the document when printed with the original version matches the 8.5x11 page perfectly, but the second version (which uses the same template) uses larger indentation, meaning some lines in the template no longer fit on a single line. The document doesn't fit on a single page anymore.
I admit to some experience with Excel macros and very limited exposure to Word
This logic works fine for a limited number of rows, but creates havoc with large numbers of rows. I decided to modify this code to produce a single Word file which I could "send" to Adobe to create a PDF where I could limit the number of pages I printed at one session.
When I do this, the document no longer formats correctly. If you compare the two pages side by side, the new version uses larger page margins (indentation is increased) causing the document to overflow its one page per row design. Both macros use the exact same template.
Here are code snippets:
' Original version
Set wrdApp = CreateObject("Word.Application")
For i = 3, lastRow
Set wrdDoc = wrdApp.Documents.Open(Filename:=C:\recap.dot")
' Process bookmarks
wrdApp.Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
Collate:=True, Background:=False, PrintToFile:=False, PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
Set wrdDoc = Nothing
Set rngDoc = Nothing
wrdApp.ActiveDocument.Close SaveChanges:=False
Next i
'================New Snippet=========
Set wrdApp = CreateObject("Word.Application")
wrdApp.Documents.Add
For i = 3, lastRow
rngDoc.InsertFile Filename:="C:\recap.dot"
'Do bookmark processing
rngDoc.InsertBreak Type:=wdPageBreak
next i
wrdApp.Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
Collate:=True, Background:=False, PrintToFile:=False, PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
Set rngDoc = Nothing
Set wrdDoc = Nothing
wrdApp.Quit SaveChanges:=False
Set wrdApp = Nothing
The fault again is that the document when printed with the original version matches the 8.5x11 page perfectly, but the second version (which uses the same template) uses larger indentation, meaning some lines in the template no longer fit on a single line. The document doesn't fit on a single page anymore.
I admit to some experience with Excel macros and very limited exposure to Word