Nrupesh

Hi all!

M new to VSTO. my using VS2005


I have 2 sheets. sheetMain and sheetCalculate and I want to change cells values of sheetMain from sheetCalculate, i tried this but it's not working

Class sheetCalculate

.

.

sub Proc
dim sheetObj as sheetMain

sheetObj.cells(2,2)=sheetObj.cells(2,2)+1

end sub
.

.

End Class


there error i get is "I have not instanciated sheetObj class" which is true, but then how can i do that i want to do because it will also not allow me to type this command dim sheetObj as new sheetMain.

Any ideas!
thanks in advance




Re: Visual Studio Tools for Office updating one from another

Dennis Wallentin

Hi NRupesh,

Does this refer to a VSTO solution If not then read the following post PLEASE READ FIRST: Non-VSTO Question/Issue Resources






Re: Visual Studio Tools for Office updating one from another

Cindy Meister

Hi Nupresh

I agree with Dennis that this looks more like an Automation question than a VSTO question. The office.developer.automation newsgroup, which you'll find in the list to which he linked would be a good place to pursue the discussion.

To give you a head start, though...

You first need a reference to the Excel object library, from the COM (not the .NET tab). You also need to declare an object variable for the Excel application and instantiate that. If you're doing so, you should include this part of your code when you ask again in the newsgroup.

Object variables for Excel worksheets and workbooks need to be declared as Excel.Worksheet and Excel.Workbook objects, then instantiated with sheets existing in a workbook / as workbooks opened in the application. Here's a Knowledge Base article that discusses automating Excel using VB.NET in some detail, with code examples. I suggest you work through that, first, before posting in the newsgroup.

http://support.microsoft.com/kb/301982/en-us

Nrupesh wrote:

M new to VSTO. my using VS2005


I have 2 sheets. sheetMain and sheetCalculate and I want to change cells values of sheetMain from sheetCalculate, i tried this but it's not working

Class sheetCalculate

.

.

sub Proc
dim sheetObj as sheetMain

sheetObj.cells(2,2)=sheetObj.cells(2,2)+1

end sub
.

.

End Class


there error i get is "I have not instanciated sheetObj class" which is true, but then how can i do that i want to do because it will also not allow me to type this command dim sheetObj as new sheetMain.

Any ideas!
thanks in advance






Re: Visual Studio Tools for Office updating one from another

Nrupesh

So what i gether from you is that even though I am working on .net Excel project, at runtime what I am trying to do is more to do with Com objects rather then managed object.

My understanding was 'cells' belonged to Class SheetMain so if i some how could instanciate the object of the class i would be able to call obj.Cells(row,cell). But now from what u say i understand that when I compile and run the application it's like a normal excel app. where all my sheets are com object and so if I need to updated any cells in those sheets i will have to do that u suggest !

Is my understanding correct




Re: Visual Studio Tools for Office updating one from another

Cindy Meister

Nrupesh wrote:
So what i gether from you is that even though I am working on .net Excel project, at runtime what I am trying to do is more to do with Com objects rather then managed object.

My understanding was 'cells' belonged to Class SheetMain so if i some how could instanciate the object of the class i would be able to call obj.Cells(row,cell). But now from what u say i understand that when I compile and run the application it's like a normal excel app. where all my sheets are com object and so if I need to updated any cells in those sheets i will have to do that u suggest !

Is my understanding correct

Yes, sort of. You're automating a COM object. There's no way to use an Office application's "classes" in memory; they must first exist as objects - in the application interface - before they can be used (automated). You can certainly abstract Excel and create classes to work with your objects (similar to how VSTO does it), but the classes have to be instantiated from existing Excel objects and the actions the classes perform must - at the deepest level - use the COM interop.