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 / February 2008

Tip: Looking for answers? Try searching our database.

Invalid merge field

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
newschapmj1 - 19 Feb 2008 08:56 GMT
We have a large collection of mail merge templates containing an "Invalid
Merge Field"  (ie field is not in the data source)

Option 1 is to add the missing field to the data source.
-i.e. an empty data item

Option 2 is to remove the missing field by VB

I have found scripts that process folders of documents.
eg http://gregmaxey.mvps.org/Process_Batch_Folder.htm

I'm not sure how to remove a mail merge field (eg "InvalidField").
Changing it is not any use to me.
I can modify the data source to prevent the "Invalid Merge Field" dialog
appearing during processing

We are using Word 2002.
macropod - 19 Feb 2008 09:17 GMT
Hi newschapmj1,

Is there a reason you can't delete the problem fields from the mailmerge templates?

Cheers
Signature

macropod
[MVP - Microsoft Word]
-------------------------

> We have a large collection of mail merge templates containing an "Invalid
> Merge Field"  (ie field is not in the data source)
[quoted text clipped - 13 lines]
>
> We are using Word 2002.
Doug Robbins - Word MVP - 19 Feb 2008 09:47 GMT
The following is a modifiation of the code in the article "Find & ReplaceAll
on a batch of documents in the same folder" at:

http://www.word.mvps.org/FAQs/MacrosVBA/BatchFR.htm

that should do what you want as long as you get the code of the mergefield
correct.

Dim mf As Field
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document

PathToUse = "C:\Test\"
'Set the directory and type of file to batch process
myFile = Dir$(PathToUse & "*.doc")
While myFile <> ""
   'Open document
   Set myDoc = Documents.Open(PathToUse & myFile)
   'Iterate through the fields in the document
   For Each mf In myDoc.Fields
       If UCase(mf.Code) = "MERGEFIELD NAMEOFMISSINGFIELD" Then
           mf.Delete
       End If
   Next mf
   'Close the modified document after saving changes
   myDoc.Close SaveChanges:=wdSaveChanges
   'Next file in folder
   myFile = Dir$()
Wend

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

> We have a large collection of mail merge templates containing an "Invalid
> Merge Field"  (ie field is not in the data source)
[quoted text clipped - 13 lines]
>
> We are using Word 2002.
 
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.