Add the excel file to the project. Go to the solution explorer and right-click the excel file and select properties. Change Copy to output directory to copy always. Now the file will be in the same directory as your exe. You can use Reflection.Assembly.GetExecutingAssemblyto get the catalog.
To add a file to the project:
Right click on the project> Add> Existing Item> Your Excel File.xls
To include a file in an assembly:
Right-click the file> Properties> Copy to Output Directory. Set this value to either Always Copy or Copy if it is newer.
Here is the code to get the path to the excel file:
Dim exeDir As New IO.FileInfo(Reflection.Assembly.GetExecutingAssembly.FullName)
Dim xlPath = IO.Path.Combine(exeDir.DirectoryName, "Your Excel File.xls")
xlPath should now be the full path to the excel file.
source
share