473,509 Members | 2,526 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Microsoft.Office.Interop.Excel

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
Nov 20 '05 #1
3 10776
"©pEIO" <peio(nospam)@email.it> schrieb
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...


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

Nov 20 '05 #2
"Armin Zingler" <az*******@freenet.de> ha scritto nel messaggio
news:40***********************@news.freenet.de...

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


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
Nov 20 '05 #3
"©pEIO" <peio(nospam)@email.it> schrieb
"Armin Zingler" <az*******@freenet.de> ha scritto nel messaggio
news:40***********************@news.freenet.de...

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)


Very thanks Armin.
But why in the PIA of Excel the wksExcel.Cells(6, 1) are declare
Object and not Excel.Range???

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

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
27165
by: Julia | last post by:
Hi, I am trying to use the Microsoft.Office.Interop.Excel.dll but I dont know how. First, how do I install it? I have tried to run the register.bat but it doesnt work. How should I do this? ...
5
27219
by: C# newbie with big problems | last post by:
Ok, I've tried everything I could come up with but nothing is working. I am creating an application which needs to post information into an excel document. I have not yet had a chance to play with...
0
2861
by: Cheryl | last post by:
I am new to C# and I am trying to convert this vba code to C#: Columns("A:A").Select Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _ TextQualifier:=xlDoubleQuote,...
9
10982
by: wendell_lucas | last post by:
Hi, I have an ASP.NET application that creates reports in Excel. It works fine in development but not on our production Windows 2003 server running IIS 6.0 Excel does not show up. I had a DCOM...
0
1622
by: pradeepkumarappagari | last post by:
by using 'Microsoft.Office.Interop.Excel.dll' can we set print settings of an excel file? if possible tell me what and all we can do by using 'Microsoft.Office.Interop.Excel.dll'.
0
1292
by: insanomania911 | last post by:
I tried everything: - the refrerence to MS OFFICE 11.0 - Installed the PIA to the Office 2003 and made sure that the files are in the assembly folder When I add the reference I only get...
0
3712
by: bfrank1972 | last post by:
I want to be able to get a list of all custom named fields in an Excel worksheet, but I am having trouble with this. In the code below, access to a field that I named "DEALCODE" works fine - I get...
1
14020
by: romcab | last post by:
Hi guys, I'm trying to manipulate excel using a C#.net and my problem is that I cannot add the namespace Microsoft.Office.Interop.Excel. Does anyone know why? Do I need to download it...
10
4970
KodeKrazy
by: KodeKrazy | last post by:
I'm trying to read an Excel worksheet and do a find/replace for all of the commas "," in any of the cells in the sheet and replace them with a dash "-" I can get as far as getting the workbook...
0
7135
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7410
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5650
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3201
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.