Microsoft Excel 11.0 object libary

A

andersmj

Hi there

I am trying to make a windows form that uses excel to store some values
entered by the user. But I am having some problems with the object
libaries. The programs I use are Visual studio.net and Excel 2003

I am pretty much foloving the instructions in a book written by Michael
Halvorson (Title: Visual Basic.Net Step By Step).

The short version is that I must add a object libary to the visual
basic project to make it work with excel.
So I click the Project menu > Add reference... > select the COM tab >
and then the book says that I must scroll down and select the Microsoft
Excel 10.0 Objevt Libary (I can see on a picture in the book that there
also is a Microsoft Excel 5.0 Object Libary).

But on my list there is Microsoft Excel 11.0 Object Libary and
Microsoft Excel 5.0 Object Libary.

So I selected the Microsoft Excel 11.0 Object Libary. But after
entering the code in the book it does not work.

Is it because of the difference between the object libaries?

I hope that some of you can help me on this

Kind regards
Anders Jensen
 
G

Guest

Did you try closing Excel and then reopening it? I have the 11.0 Version of
the Microsoft Excel Referenced. I also have the Microsoft Office Object
Library. As for the commands, it kind of depends on what they are. (I do
have 2 other references, OLE Automation and Visual Basic For Applications),
however I am running those from within Excel 2003, not studio like you.
 
J

Jezebel

Code that works with Excel 10 should also work with Excel 11. Either you've
made a mistake with your code, or the code you're copying has a mistake in
it (very common with books on programming). Can you post the error and the
line that causes it?
 
A

A Jensen

About selecting the object libary, then it is selected in Visual Basic
and not in Excel. So Excel is not open at any time.

The code the book says must be entered is (Microsoft Excel 10.0 Object
Libary):

'Decleare Excel object variables and create types
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)

When I have selected the Microsoft Excel 11.0 Object Libary then the
code must be:

'Decleare Excel object variables and create types
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet

xlApp = CType(CreateObject("Excel.Application"),
Microsoft.Office.Interop.Excel.Application)
xlBook = CType(xlApp.Workbooks.Add,
Microsoft.Office.Interop.Excel.Workbook)
xlSheet = CType(xlBook.Worksheets(1),
Microsoft.Office.Interop.Excel.Worksheet)

Note the difference betveen Excel.Application and
Microsoft.Office.Interop.Excel.Application

Kind regards
Anders Jensen
 
A

A Jensen

For some reason it works just fine now.
I was just changing out some code to paste in my reply to GB, and now
it works :)

Nice
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top