473,804 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.File SystemObject" );
var objTextFile = objFSO.CreateTe xtFile("C:\temp ", true);
var MergeTags = "Title|Forename |Surname";
var MergeData = "TestTitle|Test Forename|TestSu rname";

objTextFile.wri teline (MergeTags);
objTextFile.wri teline (MergeData);
objTextFile.Clo se;

objFSO = null;
objTextFile = null;

var objWordApp = new ActiveXObject(" Word.Applicatio n");
objWordApp.Visi ble = true;

var FName = "C:\Development \ATOFina\CBS\Te mplates\Course. doc";
var objWordDoc = objWordApp.Docu ments.Open(File name:=FName);
objWordDoc.Sele ct;

var objWordSelectio n = objWordApp.Sele ction;
var objWordMailMerg e = objWordDoc.Mail Merge;

objWordDoc.Mail Merge.OpenDataS ource(Name:="C: \temp\merge.dat ",
LinkToSource:=T rue, addtorecentfile s:=False);

objWordDoc.Mail Merge.Execute;
var objWordMerged = objWordApp.Acti veDocument;

objWordApp.Opti ons.DefaultFile Path(Path:=wdDo cumentsPath) = "C:\temp";

objWordDoc.Sele ct;
objWordDoc.Clos e;
objWordMerged.S elect;
Any comments on how I can get this to work?
Jul 20 '05 #1
2 9557
"North Country Boy" <km*******@fast mail.fm> wrote in message
news:68******** *************** ***@posting.goo gle.com...
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.File SystemObject" );
var objTextFile = objFSO.CreateTe xtFile("C:\temp ", true);
In JScript, you have to escape backslash. Put:
var objTextFile = objFSO.CreateTe xtFile("C:\\tem p", true);
var MergeTags = "Title|Forename |Surname";
var MergeData = "TestTitle|Test Forename|TestSu rname";

objTextFile.wri teline (MergeTags);
objTextFile.wri teline (MergeData);
objTextFile.Clo se;
Should be objTextFile.Clo se();
var FName = "C:\Development \ATOFina\CBS\Te mplates\Course. doc";
Should be \\ instead of \.
var objWordDoc = objWordApp.Docu ments.Open(File name:=FName);
This is wrong. Since Open method of Documents property looks:

..Open(FileName , ConfirmConversi ons, ReadOnly, AddToRecentFile s,
PasswordDocumen t, PasswordTemplat e, Revert, WritePasswordDo cument,
WritePasswordTe mplate, Format, Encoding, Visible)

you have to write:

var objWordDoc = objWordApp.Docu ments.Open(FNam e);

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

var objWordDoc = objWordApp.Docu ments.Open(FNam e,undefined,fal se);

objWordDoc.Mail Merge.OpenDataS ource(Name:="C: \temp\merge.dat ",
Same thing.
objWordDoc.Mail Merge.Execute;
Should be: objWordDoc.Mail Merge.Execute() ;
objWordApp.Opti ons.DefaultFile Path(Path:=wdDo cumentsPath) = "C:\temp";
Wrong.
objWordDoc.Sele ct;
objWordDoc.Clos e;
objWordMerged.S elect;


objWordDoc.Sele ct();
objWordDoc.Clos e();
objWordMerged.S elect();

Vjekoslav
Jul 20 '05 #2
On 20 Nov 2003 03:25:00 -0800
km*******@fastm ail.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
2072
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. Word loads, data gets pasted in and it merges fine. One problem tho, it's doing Form Letters rather than Mailing Labels Here's the code...
1
3171
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 Response.ContentType = "application/msword" Response.AddHeader content-disposition","attachment;filename=myfile.doc" but can I interate through a bunch of records and produce, say, a separate invoice for each one by merging? I know how to iterate through the...
4
8880
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 write the records to be merged into that table. The Word documents are using a system dsn (ODBC) to connect to the data source. In my code I simply open the Word documents after writing to the table do a mail merge and print. It runs pretty...
1
1739
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 in Word when it tries to import data. The message is : ********************** Opening this document will run the following SQL command: SELECT * FROM 'Tbl.' WHERE 'Fld.' = 1
5
1196
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 with some javascript using ActiveX -- is anyone aware for another way to do it
6
1825
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 the best way to do this? Is it good idea to have MSWord installed on the server? If it's not a good idea or if MSWord is not installed on the server what are the alternatives? I am using Office 2003. Thank You
7
7245
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 for any comments about the use of the docmd.transfertext method instead of the code Albert used for creating the text file. Also, perhaps some ideas for coding the Subject Line of each email so
3
2828
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 merge, but the problem with that is that it is time consuming and inefficient because there is no way to set it up to recognize commonly used entries and autofill the field. The first paragraph of the form letters look something like this (the parts...
0
1390
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 to create the file for use as a datasource in the MM. So far I have found that a fairly easy method is to output a txt file which contains a tab delimited list of the names and addresses. This can then be used as a datasource in MSWord, afterwhich...
0
9711
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9169
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5668
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.