• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1235
  • Last Modified:

Create a new ActiveX Excel Object to report data in VBSCRIPT / JAVASCRIPT

i have used the following code to open up an excel activexobject

Set xl = CreateObject("Excel.Application")

' Show Excel.
xl.Visible = True

' Open the file.
xl.Workbooks.Open "C:\test.xls"

the code however does not trigger or open up an Excel spreadsheet.

Kindly assist on how i would create a new excel object and represent my data in the cells.

thanking you
  • 4
1 Solution
is Excel installed on the server? is the xls in that folder? Permissions on that folder allow IUSR_ to open it?



It is not a question of the Extensions.. but rather one of having the registered code (the Excel Object Model DLL in this case) on the machine that you are doing the Excel file access. As you have Excel installed and registered on your machine.. all the necessary Excel program components are in place. As the Server does not have Excel installed, it does not have the necessary program code requirement.. and hence you receive the "ActiveX Cannot Be Found" error message.

To get the necessary Excel components to achieve what you want, Excel has to be installed on the Server. I know it suggz.. but Bill Gates didn't get to be a gazillionaire for doing nothing.. <sigh>.

If you can't install Excel on the Server, then you have one of two choices.

1) Lose the Excel spreadsheet and use another file type.. for data storage / retrieval.. (such as Microsoft Jet which is easily transportable.. and comes license free).

2) Have your ASP run an Out Of Process Component on a client machine that has Excel installed on it, to do all of your spreadsheet I/O. This is a much more complicated solution and let me add a much slower way to do this, but it will work if you want to put the energy into it.
RikaAuthor Commented:
Hi .. thanks for your efficient response.

firstly.. i need to create a New Excel Spreadsheet. It does not already exist.

i am not sure whether the server does have excel because i assumed that if the client had a copy of Excel it should execute of the accessing terminal.  Well u learn everyday. I'm a grad! I will look into it though and reply. :)

i tested it by popping a msgbox before the Excel open call and after the open call and the 2nd msgbox does not pop up after the
Set xl = server.CreateObject("Excel.Application")

any ideas?

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Dim ExcelObject
Set ExcelObject = GetObject(, "Excel.application")

If ExcelObject is Nothing then
Msgbox "Didn't work"
ExcelObject.Quit  'close it
End If

Do you want to save your .xls file to the server or the client.  If you want to write an ASP page that will pull data from your Access database, you can display it in your browser window as and Excel spreadsheet.  This will only work if you have Excel installed on your client machine and if you are using IE.  All you need to do is add the following line to your code.  Here is some sample code that will create a no-frills excel report.

Response.ContentType = "application/vnd.ms-excel"
     for i = 0 to studentRS.Fields.Count -1
          sNames = sNames & (studentRS.Fields(i).Name & chr(9))
     sNames = left(sNames, len(sNames) - 1)
     Response.Write(sNames) & vbcrlf
     do until studentRS.EOF
          for x = 0 to studentRS.Fields.Count - 1
               sRecord = sRecord & studentRS.Fields(x).Value & chr(9)
          sRecord = left(sRecord, len(sRecord)-1)
          Response.Write(sRecord) & vbcrlf
          sRecord = ""
If you want to create this report on the server, I do not think it's possible to do without using a COM object and having Excel installed on the server.


No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept Answer by markhoy

Please leave any comments here within the next seven days.
EE Cleanup Volunteer

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now