0

I'm receiving this unhandled exceptions trying to open an excel file through VB behind a button on a windows form: 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.'

I've tried using variations of:

Dim oXL As Excel.Application = New Excel.Application
Dim oWB As Excel.Workbook
Dim oWS As Excel.Worksheet

oXL.Visible = True
oWB = oXL.Workbooks.Open("D:\Test.xlsx")
oWS = oWB.Worksheets("Sheet1")
oWS.Activate()

and

Dim oXL As Object
oXL = CreateObject("Excel.Application")
oXL.Visible = True
oXL.workbooks.open("D:\Test.xlsx ")

The file is definitely there, I can physically see it in the folder and have copied and pasted the file path and name to avoid typos. Also I’ve used System.IO.File.Exists with a simple if statement and message box to confirm the file can be seen through VB.

I've tried the COM reference for Microsoft Office 16.0 Object Library and Microsoft Excel 16.0 Object Library and also manually browsing for C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Excel\15.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Excel.dll as suggested on a forum.

I've tried the following variations of imports:

Imports Excel = Microsoft.Office.Interop.Excel
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Excel
Imports Excel = Microsoft.Office.Interop.Excel
Imports Microsoft.Office.Core
Imports Microsoft.Office
Imports System
Imports System.Runtime.InteropServices
Imports System.IO

I can open excel files using the following line (with the filename coming from an OpenFileDialog):

Process.Start("C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE", """"" """ & strFileName & """")

I'm using Windows 10 and Office 365. Search engine results suggest there's an unresolved issue with Office 365, but I’ve so far found no solutions that work for me. Any help or suggestions will be much appreciated.

GreySaxon
  • 15
  • 1
  • 7
  • So, not a answer but.... Unless you actually 100% need to use Office Interops just don't. There are plenty of much simpler and more reliable libraries and tools to work with excel documents that hide all this sort of implementation – Hursey Jan 31 '21 at 21:52
  • You have a dependency on *two* interop assemblies, excel and office. One you got and one you don't. Manually browsing for them is a bad idea, [look here](https://stackoverflow.com/a/21018418/17034). – Hans Passant Jan 31 '21 at 21:59
  • There are two bits of information you don't provide One, you don't say that the file you want to open is an Excel workbook or whatever else. Two, you don't say that you could "manually" open the file, meaning not using VB. I also think that you inject some confusion by listing all the codes that you tried. What I would really like to see is the code that you want to work but doesn't. Perhaps you can update your question. – Variatus Feb 01 '21 at 01:31

0 Answers0