I wrote a VBscript to control a excel workbook, i don't have any problem with calling it from command line.
The problem occurs when i am trying to invoke it from html: I keep getting error saying my "RunBatch is undefined " ? ( Right now i am testing on my local and using IE 11. )
At the first place, i tried to add the url of my vbscript to (i.e as external file), since it doesn't work i add my code to "<script>"
i think the problem is on :
<input type="button" onclick=" RunBatch(fnam)" value="Click To Test" />
Here is my script:
<html>
<head>
<h1>
<title>Testing Interface</title>
</h1>
<meta http-equiv="X-UA-Compatible" content="IE=11">
</head>
<script type="text/vbscript" language="VBScript">
optioin explicit
sub RunBatch(fname)
Dim oWorkBook
Dim xlObj
Dim oShell
Dim oFS
Dim wsBatch
Dim wsBatchMap
Dim filePath
Set oShell = CreateObject("Wscript.Shell")
Set xlObj = CreateObject("Excel.Application")
Set oFS = CreateObject ("Scripting.FileSystemObject")
Set filePath = oFS.GetFolder("F:\User Files\....\Testing")
fname = filePath.Path&"\"&fname
xlObj.DisplayAlerts = False
xlObj.AskToUpdateLinks = False
xlObj.AlertBeforeOverwriting = False
xlObj.Visible = False
Set oWorkBook = xlObj.Workbooks.Open(fname,0)
Set wsBatch = xlObj.Worksheets("xx")
Set wsBatchMap = xlObj.Worksheets("xxxxx")
xlObj.Workbooks.Open(oShell.ExpandEnvironmentStrings("%APPDATA%")&"\xx.xlam")
'config ur range
wsBatchMap.Range("J6") = 1
wsBatchMap.Range("K6") = 10
xlObj.Run "XXX.xlam!xxfunction", xlObj.Workbooks(oWorkBook.Name), _
xlObj.Workbooks(oWorkBook.Name).Worksheets("xx"), _
xlObj.Workbooks(oWorkBook.Name).Worksheets("xxxx"), _
False on error resume next
if err.number <> 0 Then
on error goto 0
oShell.Echo "Runtime Error "&err.number&"workbook will be closed"
err.clear
oWorkBook.Save
oWorkBook.Close
Set oWorkBook = Nothing
if xlObj.Workbooks.Count = 0 Then
xlObj.Quit
End If
Set oWorkBook = Nothing
Set args = Nothing
Set xlObj = Nothing
Set oShell = Nothing
Set oFS = Nothing
document.write ".Done"
End sub
</script>
<body BGCOLOR="white">
<h1>Testing Interface</h1>
input Testing File Name: <INPUT TYPE="text" NAME="fname">
<br />
<input type="button" onclick=" RunBatch(fnam)" value="Click To Test" />
</body>
</html>
`
Sub RunBatch(),End Suband see if you get the same error. I'm not sure that IE still supports VBScript.