Copying from Microsoft Word to a textarea using JavaScript
I did some research and found that not many people had detailed a solution to do this so I've created my own solution. First, there's a couple things that you need to be aware of before you proceed.
- This is a client-based solution and therefore your client must have Microsoft Word installed on their machine.
- This solution accesses files on the client's machine and therefore your client must have their security settings to allow script not marked as safe to work.
So, let's get right into it:
<html>
<head><title>snook.ca load document</title>
<script language="JavaScript">
<!--//
function loadworddoc(){
var doc = new ActiveXObject("Word.Application"); // creates the word object
doc.Visible=false; // doesn't display Word window
doc.Documents.Open("C:\\My Documents\\file.doc"); // specify path to document
//copy the content from my word document and throw it into my variable
var txt;
txt = doc.Documents("C:\\My Documents\\file.doc").Content;
document.all.myarea.value = txt;
doc.quit(0); // quit word (very important or you'll quickly chew up memory!)
}
//-->
</script>
</head>
<body>
<p><input type=button onClick="loadworddoc();" value="Load">
<p><textarea name=myarea cols=50 rows=5>nothing here yet</textarea>
</body>
</html>
This is a very quick and dirty solution. There's a lot more that you can do. You'll want to reference the VBA documentation for Word. Do a search on your hard drive for "VBAWRD9.CHM". If it can't be found, you'll likely need to install the documentation off the Microsoft Office CD.
Added November 1, 2001:
Guess what? I have also included a revised version of this code that includes a browse button so users can search for word documents off their hard drive without needing to know the path. It also copies the code directly into the DHTML Editing Component (DEC).
<html>
<head><title>snook.ca load document</title>
<script language="JavaScript">
<!--//
function loadworddoc(){
// creates the word object
var doc = new ActiveXObject("Word.Application");
// doesn't display Word window
doc.Visible=false;
// specify path to document
doc.Documents.Open(document.all.hello.value);
//copy the content from my word document and throw it into my variable
var txt;
txt = doc.Documents(document.all.hello.value).Content;
//document.all.myarea.value = txt;
document.all.tbContentElement.DOM.body.innerHTML = txt;
// quit word (very important or you'll quickly chew up memory!)
doc.quit(0);
}
//-->
</script>
</head>
<body>
<p><input type=button onClick="loadworddoc();" value="Load">
<p><input type=file name=hello>
<p><textarea name=myarea cols=50 rows=5>nothing here yet</textarea>
<object ID="tbContentElement" CLASS="tbContentElement"
CLASSID="clsid:2D360201-FFF5-11D1-8D03-00A0C959BC0A" VIEWASTEXT
width="450" height="300">
<param name=Scrollbars value=true></object>
</body>
</html>
Enjoy!
TIPS, TRICKS & BOOKMARKS on WEB DEVELOPMENT
I'm Jonathan Snook and I write about web design and development. I 
Conversation
Hi Jonatan,
word.application instance in javascript
1. how I open doc with read only ?
2. how is the method to replace string1 with string2 ?
3. if for some reason there is some error,
how I "kill" the previous winword instance ?
4. the getobject to catch the current instance of word doc is working ,what is the reason ?
so I have again all the time open new instances.
any help will be appreciated
rgrds
Ell
Hi,
Thanks for your code. It was life saver.
I am able to open word document, but I am not getting the focus on the document. The document sits behind the explorer window. Is there a command to bring the document to the front and maybe set the size of the word window.
I tried opening the excel file same way, but only excel is opening, the file is not loading. Is there a reason for this?
Sree
How can I open a password protected word document without being asked to enter the password.. I would like to find a way how to pass the password through code.
Any ideas?
Thanks
Hey can I get the text in word document with its Formating....
Dion: Yes, there is a way to pass the password in the Documents.open method. The options for the open method are:
Open(FileName, ConfirmConversions, ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument, WritePasswordTemplate, Format, Encoding, Visible, OpenConflictDocument, OpenAndRepair , DocumentDirection, NoEncodingDialog)PasswordDocument is where you want to pass in the password.
Santosh: The document.Content property should get everything including formatting. You may have to go through the styles collection to grab all the style information.
I want to open an existing document using Javascript and insert values into their book marks.Can any body help me out here.Thanks
Can I use this code in Linux Operating System?
I need to display a MS Word document in a textarea or in a normal browser like netscape.
How can I do that with JavaScript?
Can you please help me in finding out solution for this..
Thanks,
RAMU
I HAVE FILES SAVED ON A FLOPPY DISK AND FORGOT MY OLD PASSWORD TO PROTECT THESE FILES IN WORD. HOW CAN I GET THE PASSWAORD OR OPEN THE FILES WITHOUT THE PASSWORD. PLEASE HELP
Probably best to do a google search for password recovery tools for Word (or Office in general). They're out there and work quickly and easily to get you back into your files.
Jonathan,
Is there a way to search for a file in the hard disk. Something like 'dir' command in windows.
thanks
Very nice code, but can u tell me how can i get with Formatting from Word file.
Shaik: to get content WITH formatting, use:
Hi There,
I would like to get a sample javascript to create a word document on a client machine without the client going on to change their browser security settings
Sorry Agbor, there's good reason why you can't create a word document on a client machine without changing security settings. If you could, any web site you went to would be able to create Word documents on your machine and you can just imagine the spamming potential of that!
Excellent script .
How would I go about searching for just 1 piece of txt .. say for example *shoe*
would I change this part
"
document.all.myarea.value = txt;
"
would I change the .all. to .shoe. ??
can you help me please
Chris: I'm not sure exactly what you're trying to do. Are you looking to replace a word within the editor with the text from Word?
No,
the script you provided at the top , displays the whole text from a document . I just want it to display 1 word from the document .
ie . look for the word shoe in a document and display it . if the word isnt there then nothing will be displayed.
Ah, I understand now!
What you need to do is replace the following line:
txt = doc.Documents(document.all.hello.value).Content;with
var findword = 'shoe';
var docrange = doc.Documents(document.all.hello.value).Content;
docrange.Find.Execute(findword);
if(docrange.Find.Found){txt=findword;}
I haven't actually tried this code but it should be close to what you need. Refer to the VBA Word documentation for more info on the Find object. The VBA documentation is (obviously?) using a Visual Basic syntax. You'll need to change the syntax to JavaScript to make it work within a web page.
Excellent thanks , it returns the value if it's found ... that what i wanted to know .
thanks for your help.
Hi Jonathan,
I need some help again if you have time.
Is there any way that I could convert the code that you provided for searching a word document , into code that will search a specific cell in an Excel Document .. say B3 ??
I've had a look all over the place and cannot find anything .
Thanks
Chris
Unfortunately, the code will require some revision to accomplish the same thing in Excel.
We should be able to change:
var findword = 'shoe';
var docrange = doc.Documents(document.all.hello.value).Content;
docrange.Find.Execute(findword);
if(docrange.Find.Found){txt=findword;}
with
var findword = 'shoe';
var cellrange = 'B3';
var isfound = doc.Worksheets(document.all.hello.value).Range(cellrange).Find(findword);
if(isfound){txt=findword;}
Again, I haven't tried it out but I hope this gives you enough direction to pull off what you need to do.
wonder if you could help me again .. i've modified the original code you provided and the excel code you provided and came up with this...
function loadExceldoc(){
// creates the word object
var doc = new ActiveXObject("Excel.Application");
// doesn't display Word window
doc.Visible=false;
// specify path to document
doc.Workbooks.Open(document.all.hello.value);
// searches cell B3 for the word shoe
var txt;
var findword = 'shoe';
var cellrange = 'B3';
var isfound = doc.worksheets('Sheet2').Range(cellrange).Find(findword);
if(isfound){txt=findword;}
document.all.tbContentElement.DOM.body.innerHTML = txt;
// quit Excel
doc.quit();
}
this loads an Excel document of my choice and searches Sheet2 Cell B3 for the word shoe ... if it finds it , it displays the word on the page.
What I want now is to remove the findword variable if possible , so that it will still search B3 and return any data thats in there ...
I do apologise for all the questions , but i'm very new to javascripting :)
thanks
Hi again,
it's okay i've managed to figure it out.
// searches cell B3 for its contents and displays the value
var txt;
var cellrange = 'B3';
var findword = doc.worksheets('sheet2').Range(cellrange);
var isfound = doc.worksheets('Sheet2').Range(cellrange).Find(findword);
if(isfound){txt=findword;}
that displays the contents of B3 ...
i'll post again with the final script for my project once complete as it may help other javascripters :)
Thankyou for your help .. I couldnt have done it without you.
you're Grade A**
i have gone thru this code.
it is gud.
but rtf files are not being opened.
my requirement is that i have a list box with all the file names of a folder.it contains doc files,rtf files,txt files,htm files.
so when ever the user clicks the file name in the list box the file content should be displayed in the textarea.
can u help me regarding this...
hi there,
loved your code, but i'm trying something diferent... i need to open MsWord, write some content and then copy it to the textarea... this is because of the MsWord speling check feature.
Can you please help me?
tks..
Hello:
Thank you so much for your code. I am trying to modify this and I am having a few problems. I have an array that loads a select box. The user makes a selection which is a category. This in turn loads via an array, the second select box which is the name of a file. I wanted the selection(the second select box) to open the document that was selected. I can get Word to come up, but I can't get the document to load. If I hard code one document it will load that one, but it will not load the "selectedDoc" variable . It says it doesn't support this. Do you have any ideas? The part that I am talking about is the line that opens the document.
function loadworddoc(){
var doc = new ActiveXObject("Word.Application"); // creates the word object
doc.Visible=true; // does display Word window
doc.Documents.Open("C:\\My Documents\\file.doc"); // specify
doc.quit(0); // quit word (very important or you'll quickly chew up memory!)
}
And this is the code of mine that loads the 2nd select box:
function getDocs(){
var selectedDoc = document.doclist.artist.value;
var song1 = document.doclist.song1;
//
for(i = song1.options.length; i >= 0; i--){
if(song1.options[i]) song1.options[i] = null;
}
//
if(selectedDoc != -1) {
for(i=0;i<arrDocuments[selectedDoc].length;i++){
song1.options[i] = new Option();
song1.options[i].text = arrDocuments[selectedDoc][i];
song1.options[i].value = arrDocuments[selectedDoc][i];
Any help is greatly appreciated.
Thanks
Kathy>
Helder: this is a code example I grabbed from the VBA docs that should get you what you're looking for:
Set myRange = ActiveDocument.Range(0, 0)
With myRange
.InsertParagraph
.InsertBefore "my text"
End With
The range will then include the newly inserted text.
hi,
can i copy the word document page by page and paste each page in a different files.
page1 to word1.doc,
page2 to word2.doc,
........e.t.c
or
page1 to html1.htm,
page2 to html2.htm,
..... e.t.c
hi,
can i copy the word document page by page and paste each page in a different files.
page1 to word1.doc,
page2 to word2.doc,
........e.t.c
or
page1 to html1.htm,
page2 to html2.htm,
..... e.t.c
Any help is greatly appreciated.
Thanks
maher
What if we set script variable RunAt="server". So can that script open files placed on server side?
Maher: I did some digging and there doesn't appear to be a way to do that. Which isn't terribly surprising. How would you handle paragraphs that split onto multiple pages?
If each page is defined as a section (unlikely) then you could split it out by looping through each
sectionobject in the document.John: there's a little more work involved as far as outputting the code onto the page but yes, you can have the code run server-side. Office needs to be installed on the server for this to work -- since it actually opens Word. Also, I've heard that there can be performance issues in doing this so be sure it's not a high traffic page.
hi
you said that :
I did some digging and there doesn't appear to be a way to do that.
my question how msword know that this is first page,second page,...e.t.c
we see that at the bottom of the each page.
I don't think there's a parent-child relationship between the pages and the content within them. I suspect Word displays the contents within two "planes". On one plane is the paging, headers, and footers. And on the other is the actual content.
This is just a suspicion and I'd gladly be proven wrong.
hi again,
can you suggest any help or can you advice me to do any thing about make word file to multi files.
thanks
maher
maher: so as not to leave you in the lurch on this issue, I don't know of any way using script to cut up based on page. However, if you have a Word document that's organized well then you could certainly split on headers. In this way, you could loop through the word document and create a new html document any time you encounter a new "Heading 2", for example.
hi Jonathan Snook
thanks very much for your help.
i solved the problem.
maher
I got an error although I have given all permissions to the IUSR_machinename.
Error Type:
Microsoft Excel (0x800A03EC)
Cannot access read-only document 'test1.xls'.
/CreateExcel.asp, line 122
var ExApp = new ActiveXObject //This is line 122("Excel.Application");
if (ExApp != null) {
ExApp.Visible = false;
ExApp.Application.Workbooks.Open("c:\\test\\test1.xls");
}
I have checked the parent folder and its children are writeable.
Please comments.
Could be a couple things... Is the document already open by another user? If not, try opening the document as read only.
Try:
ExApp.Workbooks.Open("c:\\test\\test1.xls",0,true);The 0 parameter tells Excel not to update links (otherwise, it may try and "prompt" the user and True tells excel to open the file as read only.
Thank you for the reply.
Actually, the latter part is to write the Excel sheet with data from a database table.
So I DO need to open with writable features.
I have gone through most of the examples which are Vb-based and they are just open with NO parameters.
Regarding the "readonly", it happens even the first time I boot and call the ASP page.
Please comment.
Thanks.
I have one dll file in the client machine. i want to initalize this dll file and want to work with the files. please help.
Hello Jonathan,
How can I include a table from a website (it is dynamic) in a Word doc using macro?
Usage: When the macro is run, a report will be created with the latest table.
Thanks
Hi
Excellent Script,
I search a lot because of reading a word document in ASP.
Thanks a lot,
Maybe i am being stupid, but the code does not work for me. I simply cut and paste the code on top of the post, and it does not work. I played around with alerts to see where it hangs, and it seems that the control is lost after the
var doc = new ActiveXObject("Word.Application"); line? Is this because I am working on MS word 2003? I need this script to work badly, pl help
Ashish: do you get any error messages when the script runs? Word.Application should still work regardless and it's possible that the document may still be opening but failing for other reasons. Try setting
doc.Visible=true;. This will display the Word window and may reveal any errors preventing the document from opening correctly.i get a javascript error - 'Automation server can't create object' i it something to do with Windows XP sp 2 security?
Yup. In order for this to work, your browser settings have to be set to allow Active-X controls not marked as safe to run. This is a huge security risk and should not be done without understanding the implications.
hmm then I cant use this method can I ?
Anyway can you direct me to a link that talks about the risks and how to enable it ?
can i do something on the javascript /html code that makes the ActiveX 'safe to run' ?
ashish: nothing can be done to make it safe to run. The script accesses files off of a person's hard drive so this technique is best handled either server side or via an intranet where you have more control over the machines accessing the site (in my case, I implemented this in a CMS). To enable it, go to Tools > Internet Options > Security. Click on Trustred Sites (don't modify the settings for Internet as that would allow all sites to access your system) and then click on Custom Level to adjust the settings. Click on the Sites button and add your site to the list. That should do the trick.
Thanks Jonathan. Yes I could make it work by modifying the security settings. I have reverted back to default settings though.
I am not sure if this is the right forum, but does anyone know a way of reading word documents using php on a linux (so no COM) server ?
I'm trying to pass the password of a word document (user form) to a variable with the document already open. Do you know if this is possible?
I've tried the OPEN method and it simply will not work in this situation.
Any assistance is greatly appreciated.
You don't really indicate how you're trying to pass the password in but this should work:
The three false parameters are for Confirm Conversions, Open as Read Only, and Add to Recent Files list respectively.
Jonathan
Great script. I need a help in otherway.
Need to open a new word doc, and copy the current content from the textarea to the new document, allow the users to to modify the text on the word doc, and then copy it back to the textarea.
I apprieciate your help on this
THanks
Gopal
This script runs on local machine, but when I run on server it gives me error: Automation Script Can't Create Object. Can you help me with it.
Thanks
Dimitri: there's two likely reasons that isn't working. If running client-side off a server, then it's probably a browser security settings issue. If running server-side then it's either a) server security in invoking a COM object or b) the server does not have Word (or at least the Word automation object) installed. Ensure Office is installed and try again.
Good luck!
Very nice code indeed,
but I lose the word formatting.
How can I preserve the formatting?
The following line does not seem to be working
txt = worddoc.HTMLProject.HTMLProjectItems(worddoc.Name).Text
Thanks in advance,
It is a nice pice of work. Is there anyway to pass bookmark values to a word template using this method?
Any advice ?
Regards,
Siv
this code not run from tomcat server. it gives error "Automation server cannot create object"
It's possible that you do not have Word installed on the server.
May i use the code in scripting language like php?
If i use in php i got the following error message "Automation server can't create object " .
how can i solve it?
Hi Jonathan,
Really good info you give us!
My question is: How can I trap WinWord events in JavaScript? Such as the BeforeDocumentSave event?
What I want to do is save the content into Sql Server when the user saves the doc.
Appreciate any help.
Shawn.
The code really helped me to some extent but not fully as I want to copy the text in to the textarea after clicking on hyperlink. Any help in this regard would be appreciated.
thx
Hi Jonathan,
Do you have an equivalent script for opening pdf files??
I have a loop checking for the version of Acrobat reader, but the script fails on .visible = true - object doesn't support this property or method. This is the script I am using:
for (var i = 1; i < 10; i++) {
try {
oPDF = eval("new ActiveXObject('pdf.PdfCtrl." + i + "')")
} catch(e) {
}
if (oPDF) {
break;
}
}
if (oPDF != null) {
oPDF.visible = true
oPDF.Documents.Open(sFile)
}
The value of i when the error occurs is 5, so I guess oPDF is initialised.
Any help is greatly appreciated
Simon
PDF files behave in a much different fashion. I'd be surprised if you could export any of the content using the Acrobat COM object. There may be a third-party object on the market.
is there any way to show/hide microsoft word document's toolbar when the document is inserted inside a webform using Javascript?
Thanks in Advance
Bipin
Hello Jonathan,
I had been looking for some code like this from last two days, I am glad that I am here now.
Would you have any idea on how can we do the opposite?
i.e. copy the code from html page to the word??
Thanks!
Hello Jonathan,
I had been looking for some code like this from last two days, I am glad that I am here now.
Would you have any idea on how can we do the opposite?
i.e. copy the code from html page to the word??
Thanks!
hi ,
when i tried to use ur code ,i am geting some error like "Microsoft JScript runtime error: Automation server can't create object" I installed
windows 5.6 scripter as well.but still i am getting these error..so wht is solution for this...
Thank u
Deepak
hi ,
when i tried to use ur code i.e Copying from Microsoft Word to a textarea using JavaScript ,i am geting some error like "Microsoft JScript runtime error: Automation server can't create object" I installed
windows 5.6 scripter as well.but still i am getting these error..so wht is solution for this...
Thank u
Deepak
Hi jonathan,
Do you also have a server based example to load the word document into your textarea?
Must you define the path differently?
Thank you very much
Regards,
Raf
Your tutorial is the best. I search so many website but I could not find the solution.
Thank you very much.
Hi jonathan,
Is it possible to capture an image from web cam attached to the system using javascript.actual problem is i need to capture new employee image on registration.i don't know whether it is possible or not.i tried well but no use.
it doesn't work for me!
I can open a doc and type in it but I can't retrieve the info like:
---
var txt;
txt = wordApp.Documents(filePath).Content;
document.all.myarea.value=txt;//sText;
wordApp.Quit(0);
---
I am using javascript in a html page as a localhost with IE.
Also I'd like to search for a certain style "Heading 2", but I can't make that work either!
My aim is to take a word doc and convert it in to objects (defined by the styles in word) and then put the data in to a mysql database.
Okay, found the error, my fault :'(
Can open doc, find style, retrieve text from find, and put in to a textarea and close doc. No problem.
I'd like to know the bullet value of my selection. eg "1.4.3 Some sub-title"
I have got 'Selection.Style.ListLevelNumber' to know how much it is indented (in this example it's 3) BUT I'd like to know what is the value 1.4.3
If anyone could add some help it would be nice, there are not many tutorials that go into anything more than openong and writing docs but what about reading! MSDN is not very useful... if I find another tutorial I'll put it
This foram is realy very useful.
I need some help regarding ActiveXObject.
From a parent Html I opened another html which is having 2 frames and one of them is a xls sheet.I want to use that xls to do some calculation and then on close of that opened html window I want to read a cell of that xls sheet in java script.
I am trying to use
var doc = new ActiveXObject("Excel.Application");
// doesn't display Word window
doc.Visible=false;
// specify path to document
doc.Workbooks.Open(............);
but geetting error.........
Please help me.
If possible reply me on indus@clc.lk
Thanks
Abhishek
im opening a word.application with javascript
it open and visible and works fine
im stuck on last part. when client closes that active document i need to call javascript funtion in my asp.net page.
Tell me how can i put such event in word.application object using javascript
you early response will be appericated. hoping for you alot as you mentioned you used something like this in your CMS application
Your Code is working properly
But I Want the Word Content With formatting.
You Given Some Solution like
txt = worddoc.HTMLProject.HTMLProjectItems(worddoc.Name).Text
But It Gives the Error
---------------------------
Error
---------------------------
A Runtime Error has occurred.
Do you wish to Debug?
Line: 21
Error: 'HTMLProject' is null or not an object
---------------------------
Yes No
---------------------------
Thank you for your wonderful code. It have given a biggest help to me.Thank you ! Thanks!
hai all,
can any body send me a program on
1.how to read the data from excel doc and save the data to Database in java script or jsp.
How to call and place the ms word in Internet Explorer using Java/JSP/Servlet
How to call and place the ms word in Internet Explorer using Java/JSP/Servlet. I needed very urgently. So please kindly help me.
Please help me in this task.
I have tow frames(top and bottom) in a webpage.
case 1:
------
i have a check box "load word document from server" in top frame, if i check it, a word document in "docs/" folder has to be loaded in to the bottom frame.
case 2:
------
if the check box "load word document from server" is unchecked then then i am enabling the file field, now the i browse a document file form the local system, then i need to open that file in the bottom frame.
how can i open a word file into it ?
So please help me. Thanks in Advance.
good work.
I want to capture data from a table cell in a word document
A word document is stored in the server. I want to open this document from a client machine using javascript.How?
Hi,
very nice code. But i need it in a different way. I want to save the report( a .asp file) on to clint machine.
i'll be thankful to U
vijay
Hi Jonathan,
The excel could be created the same way.
But the quit method does not work. I
actually did not have this site as reference
till i did it.
I read macros to do that.
can u please help in getting the excel to quit.
.quit(0)
.Quit
.close(0)
.Close
xlapp = nothing
xlapp = ""
Nothing of the above seems to be working to kill EXCEL.EXE in memory.
ALso. if 2 excel instances are open , will both get killed
How will i be able to get the process ID for a particular process.
I HAVE NOT USED IT ON MY SITE YET.
Hi Jonathan Snook Pls tell me how to call Ms word spell checker in javascript..
Thanks a lot.
To get formatted text, replace .Content with .HTMLProject.HTMLProjectItems.Item(1).Text.
Thus the script would read
var txt;
txt = doc.Documents(document.all.hello.value).HTMLProject.HTMLProjectItems.Item(1).Text;
How can I open a password protected word document without being asked to enter the password.. I would like to find a way how to pass the password through code.
i want open a text file for one button(View) and the contents will display in textarea field and i will make change and put save it will automatically saved
what can i do
ex: test.txt View Delete
sample.txt View Delete
Hi Jonathan,
Great code. And able work on the format of the word.
However, could teach me how to save the changes if i made?
thank you.
Hi,
I have a different requirement, may be I can get help here. I have an HTML page where I need to have a button on click of which I need to make a link and put it in the clipboard and when the user would go to Word and paste, it shld come up as a MS Word hyperlnk (niether as text nor as HTML). handling the clipboard is the easy part the problem is no code results in MS WOrd hyperlink. Any help is appreciated. Thanks
hi jonathan.nice code. but i need to get an extract from my word document not the whole text. usind the find code just gets me the word alone,but i need to get an extract from the beginnig of the document to the word "shoe". how is that possible
Hi Jon
I've view link in the jsp to open any one the document like word,
xls, rtf, pdf or txt using javascript window.open(URL will call servlet to open the document). It is opening the file in ms word, excel window
and etc.
Additionally while doing the log off, the word, pdf, exls, txt and rtf windows should be closed. As of now what ever I have open in the explorer I can able
to close it, but not able to close the word, pdf and etc.
Please let any one can help me to solve my problem using javasript. (whether I can use window handler, if so I can )
ta
Mani
Hi iam really new to this can u help me out, u did like what ever u typed in word will come into the text box , but i need exactly the opposite of that, i need to display the textbox content into the word document, if u could help me out with this, it would be of great help
Thank You very much
@sneha: I'd suspect it's the same but just reverse the two lines of code that copy the content over.
hi, i like to know whether we can call any word function (e.g grammar check) using javascript to web page.thanks.
Hii Mr. Snook,
I have read ur article and use the code, but dont know why it didn't work. Nothing is showing(Not any error msg also),just status bar "Error on this page". Please let me know wht is the problem. I have office 2003 installed in my computer but I tried also in Office 2007, its not working. Please Help!
this program is copyfolder.jsp. its showing error automated server cant create objects.. can anyone pls give a solution for this error
<html>
<body>
<script>
function copyFolder()
{
var fso = new ActiveXObject("Scripting.FileSystemObject")
fso.CopyFolder("C:\\null", "C:\\ggg\\null");
//document.Write("Created folder: " + fldr.Name);
alert("Folder is Copied");
}
</script>
<FORM NAME="demo3">
<INPUT type=button value=submit onClick="copyFolder()">
</FORM>
</body>
</html>
Hii,
I have tried this code, normaly its working fine, but not working under IIS. Can anyone help!
Hi Jonathan,
Nice job on this script. I have a problem simular to Helders' in that I need to open Word from a textarea, copy the text in the textarea to Word and any mods made to the text on close of Word needs to return back to the textarea.
I"ve gotten Word to open with the disired text using Seletion.Text, my issue comes when I close Word I can't seem to get the edits to return back to the textarea.
I am using the above script to read the content from a doc file which is saved with customised template. but when i executing the script first time, error is throwing as bad file name, do you wish to debug? second time if i execute a dialog box opening and says open the file as readonly if say yes it opens the doc file with winword. in my script doc.visible = false. can you please hlep me how to resolve this problem. i am using this script in ASP page.
Hi jonathan, the code does not work for me. I simply cut and paste the code on top of the post, and it does not work. I played around with alerts to see where it hangs, and it seems that the control is lost after the
var doc = new ActiveXObject("Word.Application"); line? Is this because I am working on MS word 2003? I need this script to work badly, pl help.
I have got a javascript error - 'Automation server can't create object' i it something to do with Windows XP sp 2 security?
can i do something on the javascript /html code that makes the ActiveX 'safe to run' ?
Even I tried in the tools to enable it, go to Tools > Internet Options > Security. Click on Trustred Sites and then click on Custom Level to adjust the settings.After doing this I don't know what I have to add in Sites button.
Pls reply ASAP
@jiya, it's best to try and load this on a web server and try from there. You'll most definitely need to set your security settings on that domain to allow the system to access Word. Word.Application is the generic reference and should work with any version but it's certainly possible it has changed over the years. Sorry I can't help you any further.
nice script, thank you very much
I have a word document with images also(not only text) , then how to get the document contents and display in html pages