Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Problem sending merge info to printer
I am running Office apps (Word, Excel) 2002 SP3 and Win XP Home.
I have a primary Excel workbook that opens a Word document using a second Excel workbook for data. In the primary Excel file, I want to click a button that opens a mail merge Word document, determine the records I want printed (from the second Excel file) and print them. I can accomplish all of these tasks but when asked to print, the records are not sent to the printer. Here's more info... Portions of the code I use are as follows: Initial declaration... Dim PreOpForm As Object, WordDoc As Object Set PreOpForm = CreateObject("Word.Application") Set WordDoc = CreateObject("Word.Document") .. .. Code to open second Excel file... Workbooks.Open Filename:="Z:\Office\Forms\Forms\Miscellaneous\Sur gery Schedule.xls" .. .. Code to open Word document... Set WordDoc = PreOpForm.Documents.Open("Z:\Office\Progress Notes\Pre & Postop Forms\Surgery Packet\€¢ Pre-Op Packet Cover Sheet.doc") .. .. Code to merge and print... Function SpoolToPrint() ' Application.ScreenUpdating = False PreOpForm.Visible = True PreOpForm.WindowState = xlMinimized PreOpForm.Activate ' ' Setting the records of the patient(s) in the surgery schedule to mail merge InitialRecord = InitialRecord - 1 NumberOfRecords = NumberOfRecords - 1 With WordDoc.MailMerge .Destination = wdSendToPrinter .SuppressBlankLines = True With .DataSource .FirstRecord = InitialRecord .LastRecord = InitialRecord + NumberOfRecords End With .Execute Pause:=False End With ' WordDoc.Close ' Application.ScreenUpdating = True End Function I obtained the merge code by creating a macro to merge info and then looking at the macro code. I have stepped through the code and the problem I encounter is this: When the line '.Execute Pause:=False' is run, instead of the appropriate merged records getting forwarded to the printer, a new MS Word document is opened (regardless of how many records are merged only 1 Word document is opened) as a copy of the original file but with the merged info present. The title of the new document is "Form Letters1.doc". I have searched this NG for answers, checked the internet and searched more help files than I care to elaborate on and cannot find a solution. In addition, I can't explain that after executing the 'PreOpForm.Activate' code, the ActiveWorkbook.Name is the main Excel file not the Word file. I cannot seem to activate the Word file with the merged info to print it using 'Printout'. If I could, I can always set up a For..Next routine to merge individual records and print them using 'Printout'. How can I do that if "PreOpForm.Activate" doesn't give focus to the Word document with the merged info? It gives focus to the Word ducmnet with the mergefields, not the merged data. I would much prefer to try and get the 'execute' statement to work. Any assistance is greatly appreciated. Thanks in advance. Boog |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Save default printer info in Excel | Excel Discussion (Misc queries) | |||
E-Mail Merge difficulties--not actually sending? | Excel Worksheet Functions | |||
Sending Info | Excel Worksheet Functions | |||
How do I turn off info box "This document was sent to the printer. | Excel Discussion (Misc queries) | |||
Sending print commands to the printer | Excel Programming |