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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automate Word Mail Merge 1

Status
Not open for further replies.

Rdhines

IS-IT--Management
Jun 14, 2002
10
US
I am trying to automate a word mail merge. The data source path changes daily. The data source will always be an XLS file. I'd like a dialog box to prompt the user to enter the folder Name and file name of the data source. Below is an example of what I cam trying to achieve.

ActiveDocument.MailMerge.OpenDataSource Name:= _
"g:\FolderName\FileName.xls", _
ConfirmConversions:=FalseReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=g:\FolderName\FileName.xls;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Passw" _
, SQLStatement:="SELECT * FROM `Sheet1$`", SQLStatement1:="", SubType:= _
wdMergeSubTypeAccess

Thanks
 




Check out Application.DisplayAlerts

Skip,
[sub]
[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue][/sub]
 


"Also, once I run the macro I get a select table dialog, can I avoid this dialog and hard code the sheet I want to select from ?"

I don't know the answer to this, but what I'd do is macro record assigning the workbook and sheet, and observe the recorded code related to selecting the sheet.

Here's an exerpt from HELP...
HELP said:
This example creates a new main document and attaches the Microsoft Excel spreadsheet named “Names.xls.” The Connection argument retrieves data from the range named "Sales."
Code:
Dim docNew As Document

Set docNew = Documents.Add

With docNew.MailMerge
    .MainDocumentType = wdCatalog
    .OpenDataSource Name:="C:\Documents\Names.xls", _
        ReadOnly:=True, _
        [b]Connection:="Sales"[/b]
End With


Skip,
[sub]
[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue][/sub]
 
Skip,

I apologise for delaying in showing you my appreciation for the time and help you have extended to me.

So I [!]Thank You[/!] very much for all the help.

Wishing you well and the very best for the holidays,
Johnny
 



Thanks Johnny!

Skip,
[sub]
[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top