Link to home
Start Free TrialLog in
Avatar of mikeyrad
mikeyradFlag for United States of America

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.
Avatar of webwoman
webwoman

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
Avatar of Kaflanko
Kaflanko

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mikeyrad

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.href)

// 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.Application")    
      if (objApp == null) { window.close() }
         objApp.Visible = true
         objApp.Workbooks.Open(sFilename)          
         break;
         
   case "doc":    
      objApp = new ActiveXObject("Word.Application")    
      if (objApp == null) { window.close() }
         objApp.Visible = true
         objApp.Documents.Open(sFilename)          
         break;
}
window.close()
</script>

</head>
</html>
Glad it worked! :D
Thanks for the points/grading ;)