Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted
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

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...