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!

Force Office documents to open in office, not the browser.

Status
Not open for further replies.

simonWMC2

Programmer
Aug 5, 2004
161
GB
(Sorry, i posted this in the wrong forum, so copied it here now - I am a numpty!)

Hi guys...

I have buit a web page that needs to link to a number of word, excel, powerpoint and access files. I want the links to open the files in the full applications rather than the web browser (ie6).

I have tried


Code:
<script language="JavaScript">
  function startWord(strFile)
  {
    var myApp = new ActiveXObject("Word.Application");
    if (myApp != null)
    {
      myApp.Visible = true;
      myApp.Documents.Open(strFile);
    }
  }
</script>
But can't get it to work.
I am using DW8 and Office 2003.
Any ideas ?

Thanks

Simon
 
If I need a user to open a file I just create a link -
Code:
<html>
<head>
</head>
<body>
<a href="Array.docx">array</a>

</body>
</html>

Do you need to use javascript?
 
Thanks. Trouble is if you do that, it opens it in the browser. I want it to open actually in word.

Thanks

Simon
 
Yes thank you.
Trouble is I need to do it from the web page. I can't mess with the client machines :(

Thank you very much for your help though! :)
 
Can you be more specific? "I can't get it to work" doesn't offer a good starting point

Cheers,
Dian
 
I put the code above into the head of a simple HTML page with several links to MS Office files. I want the files to open in the Office application (ie Word or Excel, ect).

With normal href links they open in internet explorer window, not in thew application itself. Although I do understand it can be changed by the client.

After searching and tweaking, i came up with the javascript above, but the link does nothing.
The actual link is : javascript:startWord(
Not sure how much more detailed I can be ?

Thanks
 
Where are the documents? is an URL pointing to a host called "myfile.doc" (like "yahoo.com").

I guess you'll need to used name>/myfile.doc if you have your documents available on a webserver or file://<file path> if they are in your PC

Cheers,
Dian
 
What happens if you put the same URL directly in the browser?
When you run your javascript, isn't there any messages or javascript errors?

Cheers,
Dian
 
The browser appears to do nothing. Either from the link or if you paste into the address bar.

It does show an error

Says it has an expected ] at character 15 of line 1.
line one (on my page) is :

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]

I have tried putting a ] in (even though that makes no sense), but i still get the same error....
 
Humm, if the document doesn't show when put in the URL, maybe it's not avaliable. Is it on a web server or in a shared folder?

The error doesn't need to be exactly in line one. Can you post your entire source?

Cheers,
Dian
 
Hi...

The doc is def there, cos if you ignore the javascript it opens the doc in explorer...

Here is first half of source. The rest is just a big table...

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Word - Beginners</title>
<style type="text/css">
<!--
.style3 {font-family: Arial, Helvetica, sans-serif; font-size: 12; }
.style4 {font-size: 12}
-->
</style>
<script language="JavaScript">
  function startWord(strFile)
  {
    var myApp = new ActiveXObject("Word.Application");
    if (myApp != null)
    {
      myApp.Visible = true;
      myApp.Documents.Open(strFile);
    }
  }
</script>
</head>

<body>
<div align="center">
  <table width="700" border="0" align="center" cellpadding="3">
    <tr>
      <td colspan="5" bordercolor="#000000"><div align="center"><img src="Images/logo-t2s.jpg" alt="Time2Study Logo" width="200" height="90" /></div></td>
    </tr>
    
    <tr>
      <td colspan="5"><div align="center"><span class="style3">Microsoft Word 2003 Beginners Supporting Documents</span></div></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td bordercolor="#999999"><a href="javascript:startWord([URL unfurl="true"]http://myserver/myfolder/myfolder2/4461%20Microsoft%20Word%202003%20Beginners/alignment.doc)">Alignment</a></td>[/URL]
      <td bordercolor="#999999"><div align="left"><a href="4461 Microsoft Word 2003 Beginners/DragDropMore2.doc" target="_blank" class="style3">DragDropMore2</a></div></td>
 
You could try

Code:
<a href="javascript:startWord('[URL unfurl="true"]http://myserver/myfolder/myfolder2/4461%20Microsoft%20Word%202003%20Beginners/alignment.doc')">[/URL]

With single quotes on the document name

Cheers,
Dian
 
Got excited for a moment....but no, :(
Thanks for trying though...
 
Actually the error has changed...

Now an error on
Code:
var myApp = new ActiveXObject("Word.Application");

It says : Automation server can't create object
 
I think that the error your'e getting is activex security setting related...

I tested this script...

<CODE>

<script language="JavaScript">
function openWordDoc()
{
var w=new ActiveXObject('Word.Application');
var obj;
if (w != null)
{
w.Visible = true;
obj=w.Documents.Open("C:\\docs\\test.doc");
}
}
</script>

</CODE>

and in IE8 I receive a pop-up warning about active x but can then click ok and the script continues and successfully opens word and then the document.

-- Jason
"It's Just Ones and Zeros
 
Thanks guys...

It is definatly a security setting on explorer. I am not allowed active x. However, I am now going to try in .asp......

Thanks to everyone for their help!
 
I've come across this before, once any Content is shipped to the browser, whether that be HTML or a DOC then it is up to the local machine settings which application, IE/Office/Notepad etc is used to open the content.

The ActiveX error is a common one and you will need to change the security settings, see for more information on doing this.

Greg Griffiths
Livelink Certified Developer & ECM Global Star Champion 2005 & 2006
 
I've come across this before, once any Content is shipped to the browser, whether that be HTML or a DOC then it is up to the local machine settings which application, IE/Office/Notepad etc is used to open the content.

The ActiveX error is a common one and you will need to change the security settings, see for more information on doing this.

Greg Griffiths
Livelink Certified Developer & ECM Global Star Champion 2005 & 2006
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top