p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 12th, 2006, 03:45 PM
Registered User
 
Join Date: Sep 2006
Location: , , .
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,



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old September 12th, 2006, 04:46 PM
Wrox Author
Points: 12,827, Level: 49
Points: 12,827, Level: 49 Points: 12,827, Level: 49 Points: 12,827, Level: 49
Activity: 15%
Activity: 15% Activity: 15% Activity: 15%
 
Join Date: Oct 2005
Location: Akron, Ohio, USA.
Posts: 4,029
Thanks: 1
Thanked 42 Times in 42 Posts
Send a message via AIM to dparsons
Default

What are you error messages?

"The one language all programmers understand is profanity."
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old September 13th, 2006, 10:49 AM
Registered User
 
Join Date: Sep 2006
Location: , , .
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?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old September 13th, 2006, 11:03 AM
Wrox Author
Points: 12,827, Level: 49
Points: 12,827, Level: 49 Points: 12,827, Level: 49 Points: 12,827, Level: 49
Activity: 15%
Activity: 15% Activity: 15% Activity: 15%
 
Join Date: Oct 2005
Location: Akron, Ohio, USA.
Posts: 4,029
Thanks: 1
Thanked 42 Times in 42 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."
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old September 13th, 2006, 11:14 AM
Registered User
 
Join Date: Sep 2006
Location: , , .
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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old September 13th, 2006, 11:18 AM
Wrox Author
Points: 12,827, Level: 49
Points: 12,827, Level: 49 Points: 12,827, Level: 49 Points: 12,827, Level: 49
Activity: 15%
Activity: 15% Activity: 15% Activity: 15%
 
Join Date: Oct 2005
Location: Akron, Ohio, USA.
Posts: 4,029
Thanks: 1
Thanked 42 Times in 42 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."
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #7 (permalink)  
Old September 13th, 2006, 11:25 AM
Registered User
 
Join Date: Sep 2006
Location: , , .
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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #8 (permalink)  
Old September 13th, 2006, 11:47 AM
Wrox Author
Points: 12,827, Level: 49
Points: 12,827, Level: 49 Points: 12,827, Level: 49 Points: 12,827, Level: 49
Activity: 15%
Activity: 15% Activity: 15% Activity: 15%
 
Join Date: Oct 2005
Location: Akron, Ohio, USA.
Posts: 4,029
Thanks: 1
Thanked 42 Times in 42 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."
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel macros mustafayildirim@msn.com Excel VBA 1 August 29th, 2007 11:50 PM
VBA Macros not showing up in the run macro menu d.lee84 Access VBA 9 August 21st, 2007 10:37 AM
Excel Macros with VBA kotaiah Excel VBA 1 September 11th, 2006 02:39 AM
How to get a list of macros in an Excel sheet tiyyob Excel VBA 0 January 21st, 2006 06:59 PM
How to prevent Open macros to run vemaju Excel VBA 3 December 5th, 2003 09:19 AM



All times are GMT -4. The time now is 04:33 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc