0

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" />
But I failed to fix it, searched a lot online, still get the same error

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>
 `

10
  • How about simplifying this? Try Sub RunBatch(), End Sub and see if you get the same error. I'm not sure that IE still supports VBScript. Commented Feb 22, 2015 at 22:26
  • Good call, i just find out IE 11 doesnt support vbscript :( ... So I change it to : <meta http-equiv="X-UA-Compatible" content="IE=10"> use IE 10 .... still doesn't work. any thought ? Commented Feb 23, 2015 at 0:29
  • Yeah - don't use VBScript. Also, I really doubt your script would ever have worked. You just can't do most things from a browser. In general, a browser can't access client resources, like the file system and programs installed on the client (like Excel). Commented Feb 23, 2015 at 6:02
  • Thank you John, the vbscript works well without html. I just tried a simple "hello world" one... still doesn't work :( I guess it has something to do with the security setting / Compatibility setting . Commented Feb 23, 2015 at 14:43
  • I mean you can't do these sorts of things from a web browser. They are considered serious security problems. What if a script like yours was loaded from a web site? Commented Feb 23, 2015 at 17:21

1 Answer 1

2
  1. Fix the typo "optioin explicit"
  2. Fix the invalid HTML (at least: nothing is allowed between </head><body>; move the script into the head)
  3. See that fnam has a value, when the button is pressed (maybe: onclick="RunBatch fname.value")
  4. on error goto 0 clears the Err object; the info is lost.
Sign up to request clarification or add additional context in comments.

1 Comment

Em..... thanks! I fixed the html error, removed ".value" after RunBatch, removed the space, typo, cleaned the "on error goto 0 " ....etc. it still saying "RunBatch" undefined ........ ? could it be the IE security setting or ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.