Reputation: 10297
I've got this code:
Imports Excel = Microsoft.Office.Interop.Excel
Public Class FormExcelTest_VB
Private Sub ButtonCreateExcelFile_Click( sender As Object, e As EventArgs) Handles ButtonCreateExcelFile.Click
Dim xlApp As New Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
. . .
I got it from here.
It doesn't compile, though; I get:
Type 'Excel.Application' is not defined.
Type 'Excel.Workbook' is not defined.
Type 'Excel.Worksheet' is not defined.
Being unfamiliar with VB[.NET], I thought to myself, "Self, you probably forgot to add a required reference." But then I saw that there is no "References" folder in Solution Explorer for the project (coming from the land of C#, that seems awfully strange to me).
The "helpful" msgs I get when hovering over the rejected code are:
The first one doesn't seem the likely remedy, and the following ones even less so. How am I supposed to know how to resolve (no pun intended) these undefined types?
Upvotes: 0
Views: 24265
Reputation: 1542
Upvotes: 2
Reputation: 11
It happens sometimes.
Right click on your project name in "Solution Explorer"
Select "Add Reference"
At ".NET" tab scroll and find "Microsoft Excel 12.0 Object Library"
Select it and click on "OK" button.
That's all.
Upvotes: 1
Reputation: 10297
This still seems bizarre to me, but I discovered that you add references via Project > Add Reference...
I added "Microsoft Excel 12.0 Object Library" and now it compiles.
And View > Object Browser is the path to see which References you have added, I guess; the C# way seems far "friendlier" to me.
Upvotes: 4