W.G.

I am trying to create an Automation in VB.NET using VS2005. The code was originially written in VBA as a macros in a sheet. Now I am trying to geather all the macros in one automation. Part of the code to be translated presented this type conversion error where it says (Unable to convert type System.__ComObject to ...).

In my code I am trying to use the content of cells of some range and do some mathematical manipulation. however, I could not find any way to extract the values or type of values residing in this range. when I tried to use excelworksheetfunction on them it works fine. Unfortunatly worksheetfunction does not contain all the math function I needed.please help me solve this in (VB.NET would be preferreble).

Thank you in advance for your time and co-operation.




Re: Visual Studio Tools for Office Convert type from System.__ComObject to VB.NET acceptable types

Ji Zhou – MSFT

Hi,

The following codes always work for me to get the value of cells.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

app = New Excel.Application

app.Visible = True

app.Workbooks.Add(Type.Missing)

CType(app.ActiveSheet, Excel.Worksheet).Range("A1").Value2 = 123

End Sub

In fact, there’s lot of ways to get the value of cell.You can also use the Cells property of worksheet, then you need to pass the Row and Column index. Like the following:

CType(app.ActiveSheet, Excel.Worksheet).Cells(1, "A").Value2 = 123

I hope this can help. If you still cannot get it worked, please feel free to unmark it and let me know. Then please follow up with you codes here.

Thanks

Ji






Re: Visual Studio Tools for Office Convert type from System.__ComObject to VB.NET acceptable types

W.G.

thank you Ji, that did help.