Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine if a Mail Merge Document

Status
Not open for further replies.

leahyj

MIS
May 5, 2004
107
US
I need some code to determine if a document is a mailmerge document or should I say if it has a datasource ( what do you call the document that has a datasource, "form letter").

I have tried these coding methods, but they all return False.

#1
With oMainDoc.MailMerge
.Execute
If .State = wdMainAndDataSource Then
retval = "True"
Else
retval = "False"
End If

End With

#2
If oMainDoc.MailMerge.MainDocumentType = wdNotAMergeDocument Then
retval = "Not a mail merge main document"
Else
retval = "Document is a mail merge main document."
End If
#3
With oMainDoc
If .MailMerge.MainDocumentType = -1 Then
retval = "False"
Else
retval = "True"
End If
End With

#4
If oMainDoc.MailMerge.DataSource.Name <> "" Then
retval = "False"
Else
retval = "True"
End If


Thanks for any help.
 
You option 4 above seems to be working for me. Roughly:
Code:
Function HasDataSource(FileName)
Dim ws As New Word.Application
Dim dc As Word.Document

ws.Visible = True
ws.Documents.Open FileName
Set dc = ws.ActiveDocument

If dc.MailMerge.DataSource.Name <> "" Then
    HasDataSource = True
Else
    HasDataSource = False
End If

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top