Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 16036

VS 2019 Problem with reference to Excel library - different office versions?

$
0
0
Hi

I'm working on some code in conjunction with a colleague that requires a reference adding to the Excel library in order to open an Excel file and run a macro.

I've added a COM reference to Microsoft Excel 15.0 Object Library via the usual References/Add References screen.

Here's the code:

Code:

Imports Excel = Microsoft.Office.Interop.Excel

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        RunExcelMacros("c:\test\test.xlsm", "thisworkbook.testme")

    End Sub


    Private Sub RunExcelMacros(ByVal Path As String, ByVal MacroName As String)

        Dim oXL As Excel.Application
        Dim oWB As Excel.Workbook

        oXL = New Excel.Application
        oXL.Visible = True
        oWB = oXL.Workbooks.Open(Path)

        oXL.Run(MacroName)

        oWB.Close(SaveChanges:=False)

        oXL.Quit()

        oXL = Nothing
        oWB = Nothing

    End Sub
End Class

This works absolutely fine for me. For my colleague however, he's getting the error:

System.IO.FileNotFoundException: 'Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. The system cannot find the file specified.'

This pops right at the start of the sub function.

The issue seems to be that he's running a different version of office - the v16 I believe. He's tried removing the reference and adding it afresh from his own copy of VS, but gets the same error message - referring to the v15 file. We've also tried copying/pasting in the code to a new windows form app to make sure nothing is being 'left behind' from when I added the reference - still has the error.

He tells me that from googling it seems there might be an issue with the v16 version of the library, so this may be a factor.

Could anyone suggest a solution for us please?

Thanks for reading!

Viewing all articles
Browse latest Browse all 16036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>