473,322 Members | 1,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Mail Merging in MSWord from Within Javascript

Hi

I'm trying to run the mail merge operation in MS Word from within
Javascript. I've already done this in VB but I'm having problems
trying to do the same thing in Javascript. First I am trying to create
a textfile which is the datasource for the mail merge process, then
I'm trying to run Word and mail merge.

The code I am trying to use in Javascript is:

var objFSO = new ActiveXObject( "Scripting.FileSystemObject" );
var objTextFile = objFSO.CreateTextFile("C:\temp", true);
var MergeTags = "Title|Forename|Surname";
var MergeData = "TestTitle|TestForename|TestSurname";

objTextFile.writeline (MergeTags);
objTextFile.writeline (MergeData);
objTextFile.Close;

objFSO = null;
objTextFile = null;

var objWordApp = new ActiveXObject("Word.Application");
objWordApp.Visible = true;

var FName = "C:\Development\ATOFina\CBS\Templates\Course.d oc";
var objWordDoc = objWordApp.Documents.Open(Filename:=FName);
objWordDoc.Select;

var objWordSelection = objWordApp.Selection;
var objWordMailMerge = objWordDoc.MailMerge;

objWordDoc.MailMerge.OpenDataSource(Name:="C:\temp \merge.dat",
LinkToSource:=True, addtorecentfiles:=False);

objWordDoc.MailMerge.Execute;
var objWordMerged = objWordApp.ActiveDocument;

objWordApp.Options.DefaultFilePath(Path:=wdDocumen tsPath) = "C:\temp";

objWordDoc.Select;
objWordDoc.Close;
objWordMerged.Select;
Any comments on how I can get this to work?
Jul 20 '05 #1
2 9491
"North Country Boy" <km*******@fastmail.fm> wrote in message
news:68**************************@posting.google.c om...
Hi

I'm trying to run the mail merge operation in MS Word from within
Javascript. I've already done this in VB but I'm having problems
trying to do the same thing in Javascript. First I am trying to create
a textfile which is the datasource for the mail merge process, then
I'm trying to run Word and mail merge.

The code I am trying to use in Javascript is:

var objFSO = new ActiveXObject( "Scripting.FileSystemObject" );
var objTextFile = objFSO.CreateTextFile("C:\temp", true);
In JScript, you have to escape backslash. Put:
var objTextFile = objFSO.CreateTextFile("C:\\temp", true);
var MergeTags = "Title|Forename|Surname";
var MergeData = "TestTitle|TestForename|TestSurname";

objTextFile.writeline (MergeTags);
objTextFile.writeline (MergeData);
objTextFile.Close;
Should be objTextFile.Close();
var FName = "C:\Development\ATOFina\CBS\Templates\Course.d oc";
Should be \\ instead of \.
var objWordDoc = objWordApp.Documents.Open(Filename:=FName);
This is wrong. Since Open method of Documents property looks:

..Open(FileName, ConfirmConversions, ReadOnly, AddToRecentFiles,
PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument,
WritePasswordTemplate, Format, Encoding, Visible)

you have to write:

var objWordDoc = objWordApp.Documents.Open(FName);

(if you pass FName only, of course). If you want to pass FileName and
ReadOnly parameters, you will have to write:

var objWordDoc = objWordApp.Documents.Open(FName,undefined,false);

objWordDoc.MailMerge.OpenDataSource(Name:="C:\temp \merge.dat",
Same thing.
objWordDoc.MailMerge.Execute;
Should be: objWordDoc.MailMerge.Execute();
objWordApp.Options.DefaultFilePath(Path:=wdDocumen tsPath) = "C:\temp";
Wrong.
objWordDoc.Select;
objWordDoc.Close;
objWordMerged.Select;


objWordDoc.Select();
objWordDoc.Close();
objWordMerged.Select();

Vjekoslav
Jul 20 '05 #2
On 20 Nov 2003 03:25:00 -0800
km*******@fastmail.fm (North Country Boy) wrote:
<snip>
Thank god you are trying to do this with IE proprietary "features." At
least the rest of us are safe.

--
Then there was the man who drowned crossing a stream with an average
depth of six inches.
-- W. I. E. Gates
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dan Nash | last post by:
Hi guys I wonder if you could help. I'm trying to create a bespoke interface for mail merging from an Access database in Word. At the moment, I'm just trying it with CSV files, and it works....
1
by: Morris | last post by:
Does anyone know whether it is possible to effect a mail merge to MSWord using VBScript in an asp file? I know it is possible to produce a doc file and force a download using ...
4
by: Tom Dauria | last post by:
I have an application that will be distributed remotely. In the Access application I am opening Word documents and mail merging. The Word documents are linked to a tmpLetter table. In my code I...
1
by: S Taylor | last post by:
I am running MSWord VBA code from within Access VBA that merges a Word mail merge document to the printer, using data in Access. In Office 97 it worked fine, but in Word 2003 a new message comes up...
5
by: Y.A. | last post by:
I want to start msWord on the server with an a givene file (.doc), customize the file (update it) then display it on the client machine -- all this on intranet using asp.net. I know it's doable...
6
by: Peter | last post by:
I have to write a ASP.NET application that creates MSWord document from a template and populated with data from the webpage. (Templates can reside on the server or client's hard drive.) What is...
7
by: giladp1 | last post by:
I found Albert Kallal's great "Super easy Word Merge" code in his site at: http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html Thanks Albert so much for sharing this. I am looking...
3
tdw
by: tdw | last post by:
Hi all, I am trying to create an Access database for use purely as a more efficient way to enter fields into a Mail Merge for a friend who is an attorney. Currently, I am using Word's mail...
0
by: chromis | last post by:
Hi there, I'll be working on a project soon which will involve outputting a list of names and addresses from a database, these will then be used in an MS Word Mail Merge. I need to know how best...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.