mailmerge macro glitch

clare_voiant

Board Regular
Joined
Mar 20, 2002
Messages
76
Hi,

having spent 2 days (with help) writing code to mailmerge a word document with a query from Access, Ive discovered that it only works successfully if the VB window is open but minimised.

the code is below, but would be grateful for a bit of code to insert at the beginning and the end that opens and minimises the VB window then closes it after. (this is probably not the best way of doing it, but am running out of time and my VB skills are limited)

thanks in advance

Clare :oops:

Option Compare Database
Option Explicit


Dim objword As Word.Application

Public Sub GenerateChequeLetter()
Dim strSQL As String
Dim docChequeLetter As Word.Document
Set objword = New Word.Application
MsgBox ("Warning..... Ensure All Word or Other Access Applications are closed before continuing.... This action takes a while please be patient.... its worth it..... honest")
objword.Visible = True

With objword

Set docChequeLetter = .Documents.Add(Template:="g:\P2EDocs\Cheque Letter")
With docChequeLetter.MailMerge
.OpenDataSource Name:="G:\ITT 2002-2003\Passport to Export\Passport to Export.mdb", _
LinkToSource:=True, AddToRecentFiles:=False, _
Connection:="QUERY QryChequeLetter", SQLStatement:= _
"SELECT * FROM 'QryChequeLetter'"
.Destination = wdSendToNewDocument
.SuppressBlankLines = True

With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True



End With

.Documents(1).SaveAs ("G:\P2EDocs\Docs\ChequeLetters") & CStr(Format(Now(), " DD MMMM YYYY") & ".doc")

.Application.Documents(docChequeLetter).Close wdDoNotSaveChanges


End With
Set objword = Nothing
Set docChequeLetter = Nothing
End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,221,618
Messages
6,160,873
Members
451,674
Latest member
TJPsmt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top