Locating Data in an Excel Spreadsheet

H

Hugh McLaughlin

Hello everyone and thanks for your help in advance. This
is somewhat of a continuation of a thread that I posted
about one week ago. the heart of the project requires
using ADO.Net to extract data from an Excel spreadseet
and display it in an ASP.Net page. Unfortuantely, the
format of the page changes somewhat from day to day. For
that reason, I have determined that using the Find method
in Excel is the best way to determine the starting cell
to extract. However, I am having problems with the
syntax to connect to the spreasheet to use the Find
method (I have the OLDDb part working fine once I
determine the proper cell). I tried the following:

Dim MyExcel As Excel.Application

Dim MyWorkbook As Excel.Workbook

Dim MySheet As Excel.Worksheet

Dim MyCell As Excel.Range

MyExcel = CType(CreateObject
("Excel.Application"), Excel.Application)

MyWorkbook = CType(MyExcel.Workbooks.Add,
Excel.Workbook)

MyWorkbook = MyExcel.Workbooks.Open
(Filename:="C:\IFRS1.xls", UpdateLinks:=False,
ReadOnly:=False)

MySheet = CType(MyWorkbook.Worksheets(1),
Excel.Worksheet)



MyCell = MySheet.Cells.Find("30 Year Fixed -
Program 100")

MyCell = MyCell.Offset(1)

MyCell = MySheet.Rows(MyCell.Row).Find
("Rate") 'This is the start of the data chart for this
type

Literal2.Text = "The starting cell is " &
MyCell.Text

The first line of code generated the error
message "Cannot create Active x"

I then tried:


Dim myExcel As Excel.Application
Dim myWorkBook As Excel.Workbook
Dim myCell As Excel.Range
Dim mySheet As Excel.Sheets
myExcel = CreateObject("ExcelApplication")
myWorkBook = myExcel.Workbooks.Open
(Filename:="C:\IFRS1.xls", UpdateLinks:=False,
ReadOnly:=False)
mySheet = myWorkBook.Worksheets(1)

But received the same error. I did make the reference to
the Excel object, so I am not sure what is causing this
error or how to get this working. Any help would be
greatly appreciated. Thanks.
 
M

MSFT

Just found another good article for this issue:

257757 INFO: Considerations for Server-Side Automation of Office
http://support.microsoft.com/?id=257757

Luke

"Microsoft Security Announcement: Have you installed the patch for
Microsoft Security Bulletin MS03-026?? If not Microsoft strongly advises
you to review the information at the following link regarding Microsoft
Security Bulletin MS03-026
http://www.microsoft.com/security/security_bulletins/ms03-026.asp and/or to
visit Windows Update at http://windowsupdate.microsoft.com to install the
patch. Running the SCAN program from the Windows Update site will help to
insure you are current with all security patches, not just MS03-026."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top