Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / May 2006

Tip: Looking for answers? Try searching our database.

Word 2002 - Mailmerge templates changing data source via VB

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
newschapmj1 - 07 May 2006 15:35 GMT
I have hundreds of Mail Merge templates which use a text file in a given
directory.
I want to open each template in vb and save it as a non mailmerge document

This should me to relocate the merge documents to a new directory.

Looking at other posts something like
ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument is needed.

However I get the 2 Dialog boxes
"xxx is a mail merge main document.  Word cannot find its data source"

"Remove Data Header or Remove All Merge Information " works fine but I want
an automatic process

These pop up soon after opening the document and before AutoOpen
which I have created in my normal.dot
Sub AutoOpen()
'
' AutoOpen Macro
' Macro created 07/05/2006 by JCHAPMAN
'
ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument
MsgBox "Auto open" & vbCr
End Sub

There is a thread for Peter Jamieson      2/04/2006  but as it was only one
document the change was made manually.

Any suggests will be gratefully received.
Doug Robbins - Word MVP - 07 May 2006 19:33 GMT
If you are getting that message, the data source must have been moved.

If you put all of the "Mail Merge templates" in a separate folder and
navigate to that folder when you run the following macro, it should do what
you want.

Dim MyPath As String
Dim MyName As String
Dim MMMainDoc As Document
'Suppress the display of alerts
Application.DisplayAlerts = wdAlertsNone
'let user select a path
With Dialogs(wdDialogCopyFile)
   If .Display() <> -1 Then Exit Sub
   MyPath = .Directory
End With

'strip quotation marks from path

If Len(MyPath) = 0 Then Exit Sub

If Asc(MyPath) = 34 Then
   MyPath = Mid$(MyPath, 2, Len(MyPath) - 2)
End If

'get files from the selected path and change the type
MyName = Dir$(MyPath & "*.*")
Do While MyName <> ""
   Set MMMainDoc = Documents.Open(MyPath & MyName)
   MMMainDoc.MailMerge.MainDocumentType = wdNotAMergeDocument
   MMMainDoc.Save
   MMMainDoc.Close
   MyName = Dir
Loop
Application.DisplayAlerts = wdAlertsAll

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

>I have hundreds of Mail Merge templates which use a text file in a given
> directory.
[quoted text clipped - 27 lines]
>
> Any suggests will be gratefully received.
newschapmj1 - 09 May 2006 11:51 GMT
Thanks

Application.DisplayAlerts = wdAlertsNone was really useful.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.