0

First, using VB, how can I check programmatically if Microsoft.Office.Interop.Excel is available in the Excel Object Library ? Then, if not, is there a way to add it to the reference programmatically ?

The code would be for a VB executable to access values in a spreadsheet, and calling some of the spreadsheet functions as well, if possible.

Siddharth Rout
  • 142,730
  • 17
  • 199
  • 246
Platypus
  • 41
  • 6

1 Answers1

1

Try creating the Excel object dynamically. If it succeeds, then Excel is available for use.

Private Function CreateObject(ByVal fullyQualifiedClassName As String) As Object
    Dim nspc As String = fullyQualifiedClassName.Substring(0, fullyQualifiedClassName.LastIndexOf("."c))
    Dim o As Object = Nothing
    Try
        For Each ay In Assembly.GetExecutingAssembly().GetReferencedAssemblies()
            If (ay.Name = nspc) Then
                o = Assembly.Load(ay).CreateInstance(fullyQualifiedClassName)
                Exit For
            End If
        Next
    Catch
    End Try
    Return o
End Function
Robert Harvey
  • 173,679
  • 45
  • 326
  • 490