aadams8918 Posted April 12, 2004 Posted April 12, 2004 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. Quote
Administrators PlausiblyDamp Posted April 12, 2004 Administrators Posted April 12, 2004 Have you set a reference to the Excel Object library? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
aadams8918 Posted April 12, 2004 Author Posted April 12, 2004 Have you set a reference to the Excel Object library? Probably not, how do I do that. I am new to VB as you can tell. Quote
aadams8918 Posted April 12, 2004 Author Posted April 12, 2004 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 Quote
Administrators PlausiblyDamp Posted April 12, 2004 Administrators Posted April 12, 2004 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts