MailMerge to create sql scripts in Word

User avatar
Timelord
4StarLounger
Posts: 504
Joined: 23 Jul 2010, 18:36
Location: Westlake, OHIO

MailMerge to create sql scripts in Word

Post by Timelord »

I have an excel spreadsheet that has columns of data that I want to use to mailmerge in to an SQL statement that is in Word. So I have variables in the script that I want filled with 1 row of information in Excel and then create the next script with the data from the next row.

ID# Name oldpath newpath
10 John \\here\there\ \\Monday\Tuesday\
11 Paul \\here\therf\ \\Monday\Wednesday\
12 Ringo \\here\therg\ \\Monday\Thursday\
13 George \\here\therh\ \\Monday\Friday\
14 Me \\here\theri\ \\Monday\Saturday\

the script has a set variables section:

/**** Set the variables below ****/
SET @oldpath = 'examplepath'
SET @newpath = 'examplepath'
SET @id# = 'ID#'
SET @Name = 'name'

the rest of the script should not be touched. I need to create around 1000 scripts with these values. I thought of Mail Merge as a way to do thisso if you can help with that it would be great, but if someone has an easier idea that would be great too. (or even a harder idea that does not have me manually creating 1000 scripts). Thanks!
Who will you Inspire today?

User avatar
Timelord
4StarLounger
Posts: 504
Joined: 23 Jul 2010, 18:36
Location: Westlake, OHIO

Re: MailMerge to create sql scripts in Word

Post by Timelord »

OK, so it has been well over 20 years since the last time I did a mail merge and it has changed a lot and I forgotten even more. I have now matched the fields up using the Insert Merge Field drop-down. So all good there. And I even previewed a bunch and it seems to be working. But now how do I get it to run even though I do not have recipients? Thanks
Who will you Inspire today?

User avatar
HansV
Administrator
Posts: 78475
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: MailMerge to create sql scripts in Word

Post by HansV »

Have you tried Finish & Merge > Edit Individual Documents... ?
Best wishes,
Hans

User avatar
Timelord
4StarLounger
Posts: 504
Joined: 23 Jul 2010, 18:36
Location: Westlake, OHIO

Re: MailMerge to create sql scripts in Word

Post by Timelord »

Hi Hans, I have got everything working (I should have kept plugging away and figuring it out, I just needed to set the variables) except...When it merges I choose to print it and it comes as 1 large file. I can work with that it is just annoying. I would like it to print a new Word file each time. Is there any way to do that? Maybe a print driver I do not know about?

It needs to stay readable, printing to a text doc would work too.
Who will you Inspire today?

User avatar
HansV
Administrator
Posts: 78475
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: MailMerge to create sql scripts in Word

Post by HansV »

Word does not provide built-in support for that. You can use a macro to split the resulting large document into individual documents (see for example Save Each Mail Merge Document Separately), or use an add-in such as Graham Mayor's ManyToOne.
Best wishes,
Hans

User avatar
macropod
4StarLounger
Posts: 508
Joined: 17 Dec 2010, 03:14

Re: MailMerge to create sql scripts in Word

Post by macropod »

See Send Mailmerge Output to Individual Files and Run a Mailmerge from Excel, Sending the Output to Individual Files in the Mailmerge Tips and Tricks thread at: http://www.msofficeforums.com/mail-merg ... ricks.html" onclick="window.open(this.href);return false;
Paul Edstein
[Fmr MS MVP - Word]

User avatar
Timelord
4StarLounger
Posts: 504
Joined: 23 Jul 2010, 18:36
Location: Westlake, OHIO

Re: MailMerge to create sql scripts in Word

Post by Timelord »

Thanks everyone. As it turns out the idea to split the documents was not the best idea I have ever had. I manually split them how I needed. It was much easier and provides the scripts in a way that are easier to work with. It has been 20+ years but Mail Merge has impressed me again. I am going to be able to use it a lot in the future for what we do.
Who will you Inspire today?