Microsoft.Office.Interop.Excel
(Thursday, December 23, 2004)
Found the following interesting discussion in the Newsgroups:
Microsoft.Office.Interop.Excel by:©pEIO
| Example:
Dim xlsExcel As Excel.Application Dim wkbExcel As Excel.Workbook Dim wksExcel As Excel.Worksheet
xlsExcel = New Excel.Application wkbExcel = xlsExcel.Workbooks.Open("C:\Test.xls") wksExcel = wkbExcel.Worksheets(i)
In this point I have an error of conversion because Option Strict On can't convert System.Object in Microsoft.Office.Interop.Excel.Worksheet. It's very strange because before that I install the PIA for Office 2003, the object wkbExcel.Worksheets(i) was an Microsoft.Office.Interop.Excel.Worksheet object. But I have resolved with this:
wksExcel = CType(wkbExcel.Worksheets(i), Excel.Worksheet) MessageBox.Show(CType(wksExcel.Cells(6, 1), String))
In the last istruction an exception occurred. The message like this "Cast not possible from Range type to String type". I have try with the MSDN example but the same exception occurred.
Somebody have some idea?? I'm crazy...
Thanks. Ciao. pEIO
| | | Reply: by:Armin Zingler
| | | As the message says, a Range object is returned:
dim r as excel.range
r = directcast(wksExcel.Cells(6, 1), excel.range)
msgbox(r.value) -- Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
| | | Reply: by:©pEIO
| | | Very thanks Armin. But why in the PIA of Excel the wksExcel.Cells(6, 1) are declare Object and not Excel.Range???
Thanks. Ciao. pEIO
| | | Reply: by:Armin Zingler
| | | | The type of the Cells property itself returns a Range object (see the object browser). "wksExcel.Cells(6, 1)" is actually "wksExcel.Cells.Item(6, 1)", but I don't know why the type of the Item property is not "Range" although it always returns a Range object. This might be answered in an Excel VBA group.
-- Armin
|
0 Comments:
Post a Comment