Here they are. I hope they are self-explanatory because it has been a year
and a half since I looked at them. They work for me in Word 2000-2003.
Haven't tested in Word 97.
Sub UnmergeThis()
' Written 29 August 2002 by Charles Kyle Kenyon
' Updated 23 September 2002 to attach normal.dot
' Remove merge codes from document, remove from merge status
'
' Test for template - in template only disconnect from merge but leave
merge fields active
'
On Error Resume Next
If ActiveDocument.Type = wdTypeTemplate Then
'
' Test for merge document - do not run if not merge document
'
If MergeTest() = False Then ' private function call
Exit Sub
End If
'
' Disconnect template from merge data
ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument
Application.CommandBars("MergeK").Visible = False
Exit Sub
End If
'
' Test for merge document - do not run if not merge document
'
If MergeTest() = False Then
Exit Sub
End If
'
Dim oField As Field
Dim vMsgBoxResponse As Variant
Dim sUserTemplates As String
'
' Double check with user because permanent operation
'
vMsgBoxResponse = MsgBox(Prompt:= _
"This will disconnect this document from the merge file." _
& vbCrLf & "This cannot be undone." & vbCrLf & vbCrLf _
& "Continue?", Buttons:= _
vbQuestion + vbYesNo + vbDefaultButton1, _
Title:="Continue?")
If vMsgBoxResponse <> vbYes Then
MsgBox Prompt:="No changes made to document.", _
Title:="Merge connection still active."
Exit Sub
End If
'
' OK to continue
'
Application.ScreenUpdating = False
'
For Each oField In ActiveDocument.Fields
If oField.Type = wdFieldMergeField Then
oField.Unlink
End If
Next oField
'
ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument
'
' Disconnect from template - attach normal.dot
'
sUserTemplates =
Application.Options.DefaultFilePath(wdUserTemplatesPath)
If Right(sUserTemplates, 1) <> "\" Then
sUserTemplates = sUserTemplates & "\"
End If
' sUserTemplates =
Application.Options.DefaultFilePath(wdUserTemplatesPath) & "\"
With ActiveDocument
.UpdateStylesOnOpen = False
.AttachedTemplate = sUserTemplates & "Normal.dot"
End With
Application.ScreenUpdating = True
Application.ScreenRefresh
'
End Sub
Private Function MergeTest() As Boolean
'
' Test for merge document - returns as true/false
' and displays message box if not merge document
'
If ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument Then
MsgBox "This is not a merge document."
MergeTest = False
Else
MergeTest = True
End If
End Function
It attaches the normal.dot template so that reopening the document won't
call up the datafile. The MergeTest function is just to kick you out of the
procedure if you are not in a merge document. There are comments in the code
(as well as left-over snippets commented out).
--
Charles Kenyon
Word New User FAQ & Web Directory:
http://addbalance.com/word
Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide)
http://addbalance.com/usersguide
See also the MVP FAQ:
http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
CGiannini said:
If you're willing to share your work, I'd really appreciate it - would
save me the time. Many thanks.