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.