Get MailMerge.Datasource as Document-Object?

L

Lüko Willms

Is there a way to the MailMerge.DataSource as a Word-Document-Object
(when it is a Word-Document, of course), without EditDataSource and
catching the then "ActiveDocument"?


Yours,
L.W.
 
J

Jean-Guy Marcil

Lüko Willms was telling us:
Lüko Willms nous racontait que :
Is there a way to the MailMerge.DataSource as a Word-Document-Object
(when it is a Word-Document, of course), without EditDataSource and
catching the then "ActiveDocument"?

Try this:

Dim docMain As Document
Dim docSource As Document

Set docMain = ActiveDocument
Set docSource = Documents.Open(docMain.MailMerge.DataSource.Name)

Of course, you may need to add error checking in case the current document
is not attached to a merge source:

Dim docMain As Document
Dim docSource As Document

Set docMain = ActiveDocument
If docMain.MailMerge.DataSource.Name <> "" Then
Set docSource = Documents.Open(docMain.MailMerge.DataSource.Name)
Else
MsgBox "The current document is not a mailmerge type of document.", _
vbInformation, "Error"
End If

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
D

Doug Robbins - Word MVP

ActiveDocument.MailMerge.DataSource.Name

returns the path\filename of the data source attached to a mailmerge main
document.

--
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
 
L

Lüko Willms

Am Fri, 13 Oct 2006 18:59:25 UTC, schrieb "Doug Robbins - Word MVP"
ActiveDocument.MailMerge.DataSource.Name

returns the path\filename of the data source attached to a mailmerge main
document.

Thanks for the hint.

And then
Set myDatasource = Documents(myMainDoc.MailMerge.Datasource.Name)

results in the Datasource as an object.


Yours,
L.W.
 
L

Lüko Willms

Am Fri, 13 Oct 2006 21:04:47 UTC, schrieb "Lüko Willms"
And then
Set myDatasource = Documents(myMainDoc.MailMerge.Datasource.Name)

But MS-Word rejects "C:\Eigene
Dateien\mySubdirectory\myFilename.doc" as an invalid filename... at
least before the code executes an
ActiveDocument.Mailmerge.EditDatasource. It seems that
..Mailmerge.CreateDataSource does not yet create the document, only the
following .EditDataSource does. Strange, isn't it?


L.W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top