mikeyrad
asked on
Executing MS Excel from a web page
I have recently written a web page that links to Word documents and Excel spreadsheets used within my organization. Unfortunately, there are macros in the spreadsheets that don't execute properly when the spreadsheet is executed via a hyperlink. How can I directly execute Excel from my web page? This web page is on the corporate intranet so an IE only solution is fine.
I don't think you can. Excel/Word in the browser window has limitations, I suspect running macros is one of them.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Bingo, that did it. Here's the code for the HTA:
<html>
<head>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<TITLE>Energy Services Document</TITLE>
<HTA:APPLICATION ID="oHTA"
APPLICATIONNAME="Energy Services Document"
BORDER="none"
CAPTION="no"
SHOWINTASKBAR="no"
SINGLEINSTANCE="yes"
SYSMENU="no"
WINDOWSTATE="minimize">
<script language="JavaScript">
var sFilename = unescape(window.location.h ref)
// Get the filename
var i = sFilename.indexOf("=")
if (i == -1) { window.close() }
sFilename = sFilename.substr(i + 1)
// Get the extension
i = sFilename.indexOf(".")
if (i == -1) { window.close() }
var objApp = null
// Execute the application with the filename opened
switch(sFilename.substr(i + 1).toLowerCase()) {
case "xls":
objApp = new ActiveXObject("Excel.Appli cation")
if (objApp == null) { window.close() }
objApp.Visible = true
objApp.Workbooks.Open(sFil ename)
break;
case "doc":
objApp = new ActiveXObject("Word.Applic ation")
if (objApp == null) { window.close() }
objApp.Visible = true
objApp.Documents.Open(sFil ename)
break;
}
window.close()
</script>
</head>
</html>
<html>
<head>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<TITLE>Energy Services Document</TITLE>
<HTA:APPLICATION ID="oHTA"
APPLICATIONNAME="Energy Services Document"
BORDER="none"
CAPTION="no"
SHOWINTASKBAR="no"
SINGLEINSTANCE="yes"
SYSMENU="no"
WINDOWSTATE="minimize">
<script language="JavaScript">
var sFilename = unescape(window.location.h
// Get the filename
var i = sFilename.indexOf("=")
if (i == -1) { window.close() }
sFilename = sFilename.substr(i + 1)
// Get the extension
i = sFilename.indexOf(".")
if (i == -1) { window.close() }
var objApp = null
// Execute the application with the filename opened
switch(sFilename.substr(i + 1).toLowerCase()) {
case "xls":
objApp = new ActiveXObject("Excel.Appli
if (objApp == null) { window.close() }
objApp.Visible = true
objApp.Workbooks.Open(sFil
break;
case "doc":
objApp = new ActiveXObject("Word.Applic
if (objApp == null) { window.close() }
objApp.Visible = true
objApp.Documents.Open(sFil
break;
}
window.close()
</script>
</head>
</html>
Glad it worked! :D
Thanks for the points/grading ;)
Thanks for the points/grading ;)