ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Mail Merge from Excel (https://www.excelbanter.com/excel-programming/416990-mail-merge-excel.html)

LuisE

Mail Merge from Excel
 
I have to recurrently send a workbook to users whom will manipulate the data
in the file and then will run a macro to create a Mail Merge (they have
different versions of Word) based on a template.

I 'm facing some questions:

How can I distribute the word file making sure that I can capture each
user's path in the MailMerge template (the DataSouce file) ?

I'm created a reference to Word 9 wich works fine but doesn't with Word 12,
how can I over come this?

Sub MailMerge()
Dim wdApp As Object
Dim wdDoc As Object
Set wdApp = CreateObject("Word.application")

Set wdDoc = wdApp.Documents.Open(Filename:="C:\Documents\name. dot")


With wdApp
.Visible = True
.ActiveWindow.WindowState = 0
.Activate
End With



With wdDoc.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = 2 'wdDefaultFirstRecord
.LastRecord = wdDoc.MailMerge.DataSource.RecordCount
'wdDefaultLastRecord
End With
.Execute Pause:=True
End With

wdDoc.Close savechanges:=False
Set wdDoc = Nothing
wdApp.Quit
Set wdApp = Nothing
End Sub



Thanks in advance



JP[_4_]

Mail Merge from Excel
 
You didn't mention where this code is being used. If it is being used
in Excel, and you save the workbook with a reference to the Word 2000
library, then it can be opened in Office 2000 or later, and the
project references will automatically update. For example, someone
with Office 2003 can open the workbook and it will work fine. This
will only work, however, if the workbook doesn't need to be saved;
once the workbook is saved, the references are updated and it cannot
be used by someone with Office 2000.

--JP

On Sep 12, 10:10*pm, LuisE wrote:
I have to recurrently send a workbook to users whom will manipulate the data
in the file and then will run a macro to create a Mail Merge (they have
different versions of Word) based on a template.

I 'm facing some questions:

How can I distribute the word file making sure that I can capture each
user's path in the MailMerge template (the DataSouce file) *?

I'm created a reference to Word 9 wich works fine but doesn't with Word 12,
how can I over come this?

Sub MailMerge()
* * Dim wdApp As Object
* * Dim wdDoc As Object
* * Set wdApp = CreateObject("Word.application")

* * Set wdDoc = wdApp.Documents.Open(Filename:="C:\Documents\name. .dot")

* * With wdApp
* * * .Visible = True
* * * .ActiveWindow.WindowState = 0
* * * .Activate
* * End With

* * With wdDoc.MailMerge
* * * * .Destination = wdSendToNewDocument
* * * * .MailAsAttachment = False
* * * * .MailAddressFieldName = ""
* * * * .MailSubject = ""
* * * * .SuppressBlankLines = True
* * * * With .DataSource
* * * * * * .FirstRecord = 2 'wdDefaultFirstRecord
* * * * * * .LastRecord = wdDoc.MailMerge.DataSource.RecordCount
'wdDefaultLastRecord
* * * * End With
* * * * .Execute Pause:=True
* * End With

* * wdDoc.Close savechanges:=False
* * Set wdDoc = Nothing
* *wdApp.Quit
* * Set wdApp = Nothing
End Sub

Thanks in advance



LuisE

Mail Merge from Excel
 
Thanks JP.

I'm running the code from Excel. I'm sending a daily file to the different
users for processing. I was thinking of saving iniatially the source file and
replace it with the daily file. How can I overcome the fact of the references
bieng updated??????


"JP" wrote:

You didn't mention where this code is being used. If it is being used
in Excel, and you save the workbook with a reference to the Word 2000
library, then it can be opened in Office 2000 or later, and the
project references will automatically update. For example, someone
with Office 2003 can open the workbook and it will work fine. This
will only work, however, if the workbook doesn't need to be saved;
once the workbook is saved, the references are updated and it cannot
be used by someone with Office 2000.

--JP

On Sep 12, 10:10 pm, LuisE wrote:
I have to recurrently send a workbook to users whom will manipulate the data
in the file and then will run a macro to create a Mail Merge (they have
different versions of Word) based on a template.

I 'm facing some questions:

How can I distribute the word file making sure that I can capture each
user's path in the MailMerge template (the DataSouce file) ?

I'm created a reference to Word 9 wich works fine but doesn't with Word 12,
how can I over come this?

Sub MailMerge()
Dim wdApp As Object
Dim wdDoc As Object
Set wdApp = CreateObject("Word.application")

Set wdDoc = wdApp.Documents.Open(Filename:="C:\Documents\name. .dot")

With wdApp
.Visible = True
.ActiveWindow.WindowState = 0
.Activate
End With

With wdDoc.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = 2 'wdDefaultFirstRecord
.LastRecord = wdDoc.MailMerge.DataSource.RecordCount
'wdDefaultLastRecord
End With
.Execute Pause:=True
End With

wdDoc.Close savechanges:=False
Set wdDoc = Nothing
wdApp.Quit
Set wdApp = Nothing
End Sub

Thanks in advance





All times are GMT +1. The time now is 03:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com