Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.beginners
|
|||
|
|||
![]()
I am opening a mail merge main document with the following code behind
it. My current method involves controlling everything from the mail merge main document, with a loop using DoEvents. This seems rather cumbersome. It would be neat if I could put some VBA behind the Document_Close event of the mail merge result file. Ideally, I'd like to pass the queue name by parameter which would be written into my word document directly, so I don't have to read it from the file again Option Explicit Private Sub Document_Open() Dim sDataSrc As String Dim sThisDoc As String sThisDoc = ThisDocument.Name sThisDoc = Left(sThisDoc, Len(sThisDoc) - 4) & "Data.doc" sDataSrc = ThisDocument.Path & "\" & sThisDoc 'Skip MailMerge if data source not present.... On Error Resume Next MailMerge.OpenDataSource sDataSrc If Err Then GoTo Done MailMerge.Execute 'This created mail merge document ActiveDocument.Saved = True ThisDocument.Saved = True Done: SetNonFinePrint WaitForClose End Sub Sub SetFinePrint() Dim iHandle As Integer Dim sPrinter As String 'FinePrint will always be the first row in the file iHandle = FreeFile Open "C:\PRINTERS.DAT" For Input As #iHandle Input #iHandle, sPrinter ActivePrinter = sPrinter Close #iHandle End Sub Sub SetNonFinePrint() Dim iHandle As Integer Dim sPrinter As String 'FinePrint will always be the first row in the file iHandle = FreeFile Open "C:\PRINTERS.DAT" For Input As #iHandle Input #iHandle, sPrinter If Not EOF(iHandle) Then Input #iHandle, sPrinter End If ActivePrinter = sPrinter Close #iHandle End Sub Sub WaitForClose() Dim iCount As Integer iCount = Documents.Count Do Until Documents.Count < iCount DoEvents Loop SetFinePrint Application.Quit End Sub The reason for doing all of this is my need to manipulate print queues around the opening and closing of the mail merge result document. The trouble being, that setting ActivePrinter in a word document changes the system's default print queue, whereas setting it in excel is only temporary within that workbook, it doesn't change the system default -- Mike |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Putting an Excel pivot report in a letter in Word! | New Users to Excel | |||
Excel 2003 - Putting an email/word document into a cell | Excel Discussion (Misc queries) | |||
EVEN AFTER PUTTING CODE IN VB, THE MESSAGE 'WORKBOOK CONTAINS LINK' POPS UP- HOW TO GET OVER THIS | Excel Discussion (Misc queries) | |||
Putting a word into a cell. | New Users to Excel | |||
Putting Excel Charts into a Word document that's getting too big | Charts and Charting in Excel |