Help with declaring types

aadams8918

Newcomer
Joined
Apr 12, 2004
Messages
3
I am trying to create an Excel worksheet from .Net. I found some code from another thread, but when I use it - I am getting an error. Please help.

(This is the Code)
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
xlApp = CType(CreateObject("Excel.Application"), Excel.Application)
xlBook = CType(xlApp.Workbooks.Add, Excel.Workbook)
xlSheet = CType(xlBook.Worksheets(1), Excel.Worksheet)

(Error message)

Type 'Excel.Application' is not defined.

I assume that I need an import statement for this, but not sure.
 
aadams8918 said:
I am trying to create an Excel worksheet from .Net. I found some code from another thread, but when I use it - I am getting an error. Please help.

(This is the Code)
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
xlApp = CType(CreateObject("Excel.Application"), Excel.Application)
xlBook = CType(xlApp.Workbooks.Add, Excel.Workbook)
xlSheet = CType(xlBook.Worksheets(1), Excel.Worksheet)

(Error message)

Type 'Excel.Application' is not defined.

I assume that I need an import statement for this, but not sure.


Ok, I figured it out. Add Reference from the menu. How easy was that.

Thanks
 
On the project menu go to add reference, then select the COM tab.
If you scroll down you will see a line that says something like
'Microsoft Excel 11.0 Object Library'
it changes slightly depending on the version. Highlight the line and press select then OK. Try and compile it again and see what happens.
 
Back
Top