Activating an invisible app

B

Barry Gilbert

I'm trying to automate a MailMerge from a VB6 app. I want to merge and then
prompt for a printer without displaying the Word UI. Here's my code so far:

Set wordDoc = wordApp.Documents.Open(FileName:=TEMPLATE_ROOT &
"PhoneListMasterMerge.doc", _
ReadOnly:=True, Visible:=False)
wordApp.Visible = False
strSQL = "SELECT Building, Name, Extension, Pager FROM " & queryName

With wordDoc
.MailMerge.OpenDataSource Name:=DATA_SOURCE, LinkToSource:=True, _
Connection:="DSN=MS Access
Database;DBQ=G:\WFD_Systems_PUB\MMApps\Distribution\" & _
"Distribution_be.mdb;DriverId=25;FIL=MS
Access;MaxBufferSize=2048;PageTimeout=5;", _
SQLStatement:=strSQL

.MailMerge.DataSource.FirstRecord = wdDefaultFirstRecord
.MailMerge.DataSource.LastRecord = wdDefaultLastRecord
.MailMerge.Execute (True)
.MailMerge.Destination = wdSendToPrinter
.Application.Options.PrintBackground = False
.Application.Activate
.Application.Visible = False
.Application.Dialogs(wdDialogFilePrint).Show
End With

Ideally, I want to display Word's print dialog without displaying Word. This
works, sort of. The problem is that. because the mail merge takes so long
(~30 seconds), I anticipate users navigating away from the VB6 app. I
therefore need to call Application.Activate. However, this seems to only work
if the Application object is visible. What am I missing here?

Of course, this wouldn't be necessary if the MailMerge were quicker. I'm
using ODBC to an Access db on a network with around 800 records. Any ideas on
how to speed this up?

Thanks in advance,
Barry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top