Home  |  Index  |  Dotnet4all Snippets  |  Submit resources
About  |  Mail us  
Dotnet4all Logo

  Microsoft.Office.Interop.Excel (Thursday, December 23, 2004)




Found the following interesting discussion in the Newsgroups:

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



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

 






0 Comments:

Post a Comment

 
Previous Posts
    - Catching "Came from Row" on a RowChange in Datagri...
    - Delete Option on a Right Click Menu?
    - How to open a new browser
    - Opening an existing file on my PC
    - Convert charref ({) to normal letters
    - Convert charref ({) to normal letters
    - Using projects
    - Help with Datagrid events please.
    - Quotes within a text string
    - Quotes within a text string

Archives
    - 10/03/2004 - 10/10/2004
    - 10/10/2004 - 10/17/2004
    - 10/17/2004 - 10/24/2004
    - 10/24/2004 - 10/31/2004
    - 10/31/2004 - 11/07/2004
    - 11/21/2004 - 11/28/2004
    - 11/28/2004 - 12/05/2004
    - 12/05/2004 - 12/12/2004
    - 12/12/2004 - 12/19/2004
    - 12/19/2004 - 12/26/2004
    - 12/26/2004 - 01/02/2005
    - 01/23/2005 - 01/30/2005
    - 01/01/2006 - 01/08/2006
    - 09/24/2006 - 10/01/2006

Disclaimer & Terms of Use  | DotNet4All.Com concept & © 2004 - 2007 by  Zelders²  - Holland