We help IT Professionals succeed at work.

VBScript......CreateObject("Excel.Application") is failing when run in web page.

jlininger asked
Medium Priority
Last Modified: 2011-08-18
I wrote a vbscript that I need to run (client side) everytime someone visits an intranet page. Basically the vbs creates an excel.application object writes some data to the spreadsheet and then saves it. I created a test html page and inserted the vbscript and it works fine when I run it from my pc. But if I try to run it from a server, or even another computer it fails when it tries to create the excel.application object. It says the activeX object couldn't be created. Why? Can someone help please?? Here is some test vbs code I inserted into a test page, it fails when I run it from anywhere but my pc.

<Script language="vbscript">

Dim objexcel

Set objExcel = createobject("Excel.application")   <----------- This is where it's failing

objexcel.Visible = True


objexcel.Cells(1, 1).Value = "Testing"


Watch Question

VBscript is a client side scripting language.
You wont have permissions to save a file on client side.
Also the object should objExcel  be installed on the client system
Or else you will get error.


I am trying to save the file on the client side, for example, the script resides in an html on a server, I want to be able to open the html from any pc on the network using internet explorer, and have the vbs run and save the file on the client pc. Is there any way to accomplish this? Do I need to use something other than vbs?
Check this example. It creates a simple txt file...
Before writing you will get a security message.........

dim filesys, filetxt, getname, path
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.CreateTextFile("c:\somefile.txt", True)
path = filesys.GetAbsolutePathName("c:\somefile.txt")
getname = filesys.GetFileName(path)
filetxt.WriteLine("Your text goes here.")
If filesys.FileExists(path) Then
  document.Write ("Your file, '" & getname & "', has been created.")
End If

Like I said the client system must have excel.
Or else it wont be able to create the object.

Ofcourse, even after that you will get atleast one security/warning message.
One alternative is create a .csv (comma seperated file) file.
It is just a plain text file but the values are seperated by commas.
this file can be opened from excel.


The client system does have excel. And the script works on the client system when the html resides on the client system, but when I move it up to the server and run it from there, it won't create the excel.application object. I also tried your example script above to create a txt file. Same problem, it runs fine when the script is on my pc. But when I move it up to the server and try to run it from there I get "cannot create activeX object "scripting.fileSystemObject"... Same thing as excel, either way, it's not creating the object. Any idea why?

Many systems will have their Filesystemobjects disabled for security reasons.


Thanks for trying to help. I looked that document over and it doesn't really have anything to do with my problem.

... and the filesystemobject is not disabled. I can run the script on all of these pc's and it works fine. The problem is not with the script. The problem is when I copy the script over to another computer and try to run it from another computer.

Just to be clear on what I am trying to accomplish.... I have inserted vbscript into an html document, the vbscript is supposed to open excel (or even a txt file would be fine for now), enter some data, and then save the document. the script works great, I have tested it, and it even works fine when I insert the vbscript into an html document and open it with IE, but here's the problem. It only works if I open the html document with the same computer that it resides on. In other words, if I map a drive to some server and run the script from there, or if I try to open the html document from our web server the vbscript fails. I get an error saying the excel.application object could not be created.. Actually I have tried other things and I get an error when trying to create any COM object. Does anyone know why this is happening? Am I approaching this the wrong way by trying to use vbs. Is there some other way I can get an intranet page to open excel enter data and save the document on a client side pc?

I think this would depend on the webserver rights, as to, if it can create any files on the server's own file system and/or client.



have the user add your server as a trusted site, then try again


warturtle,  yeah that makes sense. although, the script is failing at the point where it is trying to create the COM object "excel.application", and before it is even trying to save the file. However, I did check the permissions and made sure everything was correct. Also to eliminate file system permissions as the possible cause I temporarily allowed "everyone" full access to the entire file system on the client pc and still had the problem.

Maybe it's something with internet explorer permissions, because I can run the vbscript by itself from another pc and it works fine, it only fails when I insert it into an html doc and try to run it with IE. I've noticed some quirky things about adding vbscript to html, like when you try to use wscript.quit, or wscript.sleep it says "wscript object not found" you can only seem to use automation objects that you created a reference to.

Kavar, I can't add it as a trusted site because it's not secured, (not https).. but also a good idea.

yes you can, just uncheck the box for secure


yeah, I realized that. Thanks =)  Adding the site as trusted fixed a cross domain problem I was having. But the vbscript is still erroring out when it tries to create the excel.application object. I figured out a semi-solution. Instead of inserting the script in the hrml, I just linked the script so someone clicks on it and it runs the script. They have to click "open" on the popup box but it's no big deal. Anyone know a way to keep the "open/save" prompt from popping up for a vbs? probably impossible. =) Thanks for all of the suggestions. I'll leave this open for a little while incase anyone has anything to add, then I'll split the points up. Thanks again!
Unlock this solution and get a sample of our free trial.
(No credit card required)


Ivan, Your're totally right. Unsafe ActiveX controls were disabled, that's why it wouldn't create the excel object. I enabled it and the script is running fine in the browser, just the way I wanted it. The drawback is I'm going to have to change that setting for anyone that is going to be using it, but oh well. Do you by chance know how to "sign" a script to mark it as safe?
You need to use group policy to configure the security settings for IE on the clients.  This is big change though if you haven't got your head around group policy.

Even for small organisations, group policy rocks.  The only downside is that *all* targeted clients get exactly the same settings and only those settings so there's not much room for customising individual browsers if this is required.  You can do this with policy inheritance but it gets messy real fast.

Try using Server.CreateObject("Excel.Application"), instead of Createobject("Excel.Application").  Here is a link explaining.


Please reward me with points.


I have written a number of webpages that have created Excel documents, but I have never had the specific need to use client side VB Script to specifically create the Excel Spreadsheet on the client site.

Is there a reason why you need to specifically run Excel on the client side?  It seems to me the problems you are having stem from permissions issues or security issues or trusted site issues.

I have found it easier to create an .asp page that runs server side (on IIS).  Usually I have the .asp page create a .csv file, save it to disk, and then redirect the end user to the created .csv file.  Its a great way to export data from a database with a web interface.

Also, I have had a few specific instances whereI needed to create a spreadsheet complete with data in four separate tabs.  My solution was to use the  Server.CreateObject("Excel.Application") mentioned by icanhelp, populate the data, save the speadsheet, and redirect to the file.  Its slow and cumbersome, but its faster than cutting and pasting by hand, and the end result is what I want.

Hope this helps.

Did you distribute points yet?


Yeah, I distributed the points when I closed it a year ago. Notice the date is 4/9/04?
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.