Question

I have the following code:

Option Strict Off
Option Explicit On
Imports Excel = Microsoft.Office.Interop.Excel
Imports System
Module modXLS

    Public Function ReadXLS(ByVal uPath As String) As String

        Dim xl As New Excel.Application
        Dim xlwbook As Excel.Workbook = xl.Workbooks.Open(uPath)

        (... some not so important code...)

    End Function
End Module

However, VS2012 tells me that

 Dim xl As New Excel.Application

"xl" is an undefined type. I don't know why. I thought I imported the Excel interop.

Thank you for the help!

Was it helpful?

Solution

The problem was that I did not add a reference to "Microsoft.Interop.Excel" to the project, but I am confused why I had to do that at all. I already said

"Imports Excel = Microsoft.Office.Interop.Excel"

and the IDE did not complain about it.

Also, I was unable to find this lib in the COM / Assembly search window.

I had to browse for it, and I found it under

C:\Windows\assembly\GAC\Microsoft.Office.Interop.Excel\12.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Excel.dll

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top