Solved

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

Posted on 2004-04-08
22
221,730 Views
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.Workbooks.add

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

objexcel.ActiveWorkbook.SaveAs("c:\exceltest.xls")
objexcel.Quit

</SCRIPT>
0
Comment
Question by:jlininger
  • 7
  • 7
  • 2
  • +5
22 Comments
 
LVL 12

Expert Comment

by:venkateshwarr
Comment Utility
VBscript is a client side scripting language.
You wont have permissions to save a file on client side.
0
 
LVL 12

Expert Comment

by:venkateshwarr
Comment Utility
Also the object should objExcel  be installed on the client system
Or else you will get error.
0
 
LVL 1

Author Comment

by:jlininger
Comment Utility
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?
0
 
LVL 12

Expert Comment

by:venkateshwarr
Comment Utility
Check this example. It creates a simple txt file...
Before writing you will get a security message.........

<SCRIPT LANGUAGE="VBScript">
<!--
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.")
filetxt.Close
If filesys.FileExists(path) Then
  document.Write ("Your file, '" & getname & "', has been created.")
End If

//-->
</SCRIPT>
0
 
LVL 12

Expert Comment

by:venkateshwarr
Comment Utility
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.
0
 
LVL 12

Expert Comment

by:venkateshwarr
Comment Utility
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.
0
 
LVL 1

Author Comment

by:jlininger
Comment Utility
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?
0
 
LVL 12

Expert Comment

by:venkateshwarr
Comment Utility
0
 
LVL 12

Expert Comment

by:venkateshwarr
Comment Utility

Many systems will have their Filesystemobjects disabled for security reasons.
0
 
LVL 1

Author Comment

by:jlininger
Comment Utility
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?
0
 
LVL 16

Expert Comment

by:warturtle
Comment Utility
Hi,

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.

Regards,

Warturtle
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 10

Expert Comment

by:Kavar
Comment Utility
have the user add your server as a trusted site, then try again
0
 
LVL 1

Author Comment

by:jlininger
Comment Utility
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.
0
 
LVL 10

Expert Comment

by:Kavar
Comment Utility
yes you can, just uncheck the box for secure
0
 
LVL 1

Author Comment

by:jlininger
Comment Utility
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!
0
 
LVL 2

Accepted Solution

by:
Ivan_Skrinjaric earned 250 total points
Comment Utility
One more thing.

Under trusted sites / security click Custom Level and enable Initalizing and Scripting ActiveX controls that are not marked safe. That should enable createobject on client.

0
 
LVL 1

Author Comment

by:jlininger
Comment Utility
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?
0
 

Expert Comment

by:TEAMnetwork Systems
Comment Utility
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.
0
 
LVL 4

Expert Comment

by:icanhelp
Comment Utility
Try using Server.CreateObject("Excel.Application"), instead of Createobject("Excel.Application").  Here is a link explaining.

http://www.4guysfromrolla.com/webtech/043099-1.shtml#postadlink

Please reward me with points.

thanks.
0
 

Expert Comment

by:WebmastuhB
Comment Utility
jlininger,

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.
0
 
LVL 4

Expert Comment

by:icanhelp
Comment Utility
Did you distribute points yet?
0
 
LVL 1

Author Comment

by:jlininger
Comment Utility
Yeah, I distributed the points when I closed it a year ago. Notice the date is 4/9/04?
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now