Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open Excel, run macro, use as recordset

Status
Not open for further replies.

meldrape

Programmer
May 12, 2001
516
US
Greetings,

I have an excel macro in a spreadsheet that imports a log file into another spreadsheet, then saves it. I would like to be able to open Excel from an Active Server Page, run the macro, and use the spreadsheet as a recordset. Is there any way I can do this? I've been searching like crazy and can't find anything that comes close. I think if I can just get some help on how to run the macro from the ASP, I can figure out the rest... Many thanks for your thoughts.
 
Poked around some more and finally figured it out:
Code:
Dim xls
Set xls = CreateObject("Excel.Application")
xls.Application.Visible = true
' 3 is the value for "xlReadOnly"
ExcelFilePath="c:\testdir\book1.xls"
xls.Workbooks.Open ExcelFilePath, 3, False
xls.Run("Book1.xls!auto_open")
xls.Application.Quit 
Set xls = Nothing

set oConn = server.createobject("ADODB.Connection")
set oRs = server.CreateObject ("ADODB.recordset")
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
           "Data Source=c:\testdir\accesslog.xls;" & _
           "Extended Properties=""Excel 8.0;"""
oRS.Open "Select * from [Sheet1$]", oConn, adOpenStatic
for each fld in oRs.fields
Response.Write fld.value & "<br>"
next
oConn.Close

That's good enough for me. Works like a charm and I can customize it all I want. Many thanks for anyone out there trying to help me out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top