Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 12th, 2006, 02:45 PM
Registered User
 
Join Date: Sep 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to Run Excel Macros from ASP

Hi Friends,

Hope you all are doing well.

I want to call an existing Excel macro from ASP.

I see many variations of...

Set objExcel = New Server.createobject("Excel.Application")
.
.
.
objExcel.Run("macro-name")

but doesn't work.

My ASP doesn't seem to understand Excel.Application and .Run command.

Need help ASAP.

Thanks,

Regards,



 
Old September 12th, 2006, 03:46 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

What are you error messages?

"The one language all programmers understand is profanity."
 
Old September 13th, 2006, 09:49 AM
Registered User
 
Join Date: Sep 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In my Excel I have a simple function that inserts 1 into range("A1")
Sub test()
    Range("a1") = 1
End Sub

The ASP script looks like this:
Dim cnnExcel
Set cnnExcel = server.CreateObject("ADODB.connection")
cnnExcel.open "DBQ=" & Server.MapPath("fpdb/book1.xls") & ";" & _
    "DRIVER={Microsoft Excel Driver (*.xls)};"
cnnExcel.Run("test")

With error message:
# Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E37)
[Microsoft][ODBC Excel Driver] The Microsoft Jet database engine could not find the object 'Run'. Make sure the object exists and that you spell its name and the path name correctly.
/testexcel.asp, line 25

When I try ASP script:
Dim xls
Dim cnnExcel
Set cnnExcel = server.CreateObject("ADODB.connection")
cnnExcel.open "DBQ=" & Server.MapPath("fpdb/book1.xls") & ";" & _
    "DRIVER={Microsoft Excel Driver (*.xls)};"
Set xls = Server.CreateObject("Excel.Application")

The ASP doesn't recognize Excel.Application causes this error message:
    * Error Type:
      Server object, ASP 0178 (0x80070005)
      The call to Server.CreateObject failed while checking permissions. Access is denied to this object.
      /testexcel.asp, line 22

Any Help?

 
Old September 13th, 2006, 10:03 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Why are you trying to create an ADO connection to the Excel workbook?? The reason, in your first example, that the Jet Driver doesn't recoginize .Run is because .Run isn't part of an ADO object.

What you should be doing is something like this:

Dim xls
Set xls = CreateObject("Excel.Application")
xls.Workbooks.Open [Path to excel file], 3, False
xls.Run("[workbook].[macro]")
set xls = Nothing

"The one language all programmers understand is profanity."
 
Old September 13th, 2006, 10:14 AM
Registered User
 
Join Date: Sep 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

with the code above I get this message.

Error Type:
Microsoft VBScript runtime (0x800A0046)
Permission denied: 'CreateObject'

Can someone tell me why its denying me permission to createobject? The excel isn't read-only and I am the admin.

 
Old September 13th, 2006, 10:18 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Try Server.CreateObject though that shouldnt make a difference. What you may want to look at is the premissions of the folder the excel file resides in.

"The one language all programmers understand is profanity."
 
Old September 13th, 2006, 10:25 AM
Registered User
 
Join Date: Sep 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

With that I've got:

The call to Server.CreateObject failed while checking permissions. Access is denied to this object.

I've also tried New server.createobject, New createobject with no success.
But createobject(ADODB.connection) and createobject(ADODB.recordset) works. So my createobject is fine its just that its preventing me access to Excel.Application for some reason.

 
Old September 13th, 2006, 10:47 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Read these:

http://www.aspemporium.com/support.aspx?PRB020

Related to Word but should be helpful:

http://p2p.wrox.com/archive/beginnin...2002-12/51.asp

"The one language all programmers understand is profanity."





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to prevent Open macros to run vemaju Excel VBA 4 June 7th, 2013 12:26 PM
Excel macros [email protected] Excel VBA 1 August 29th, 2007 10:50 PM
VBA Macros not showing up in the run macro menu d.lee84 Access VBA 9 August 21st, 2007 09:37 AM
Excel Macros with VBA kotaiah Excel VBA 1 September 11th, 2006 01:39 AM
How to get a list of macros in an Excel sheet tiyyob Excel VBA 0 January 21st, 2006 06:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.