Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When im trying to open an existing excel file i keep getting this message, and it is not just for this file, any file that i create. I placed the values in the same folder with application.exe, as well as tried in different folders. Has anyone had similar problem? When i create a txt.file in that same folder it opens easily so it must be something with excel that im missing.
System.Runtime.InteropServices.COMException: 'Sorry, we couldn't find Values.xlsx. Is it possible it was moved, renamed or deleted?'

What I have tried:

Imports Microsoft.Office.Interop
   Imports Microsoft.Office.Interop.Excel
   Imports System.IO

xlApp = New Excel.Application
xlWorkbook = xlApp.Workbooks.Open("Values.xlsx")  
xlsheet = CType(xlWorkbook.Sheets(razinaString), Excel.Worksheet)
xlApp.Visible = True
Posted
Updated 28-Mar-20 23:08pm
Comments
phil.o 28-Mar-20 21:08pm    
Have you tried an absolute path to the file instead of a relative one?
Have you tried placing the file in the "ProgramData" folder?
Marc Kane 29-Mar-20 7:01am    
For some reason it works with an absolute path, but i need it to work with this relative one, cant figure out why it wont open
Edit:
I used this lines to open the file, now it opens
Dim Path As String = "Values.xlsx"
Path = System.IO.Path.GetFullPath(Path)
xlWorkbook = xlApp.Workbooks.Open(Path)

You need to place the file in the same directory as the program. However, that is only a temporary (quick and dirty) fix.

What you should really do to make it work properly is to stop using harcoded names in your source code. Use an OpenFileDialog Class (System.Windows.Forms) | Microsoft Docs[^] so you can always locate the file yourself.
 
Share this answer
 
Quote:
System.Runtime.InteropServices.COMException: 'Sorry, we couldn't find Values.xlsx. Is it possible it was moved, renamed or deleted?'

Make sure the directory, in which you try to open the file, is the one you expect. or tell the directory where the file is.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900