I try to open an Excel file in C#, but I get this error:
System.Runtime.InteropServices.COMException HResult=0x800A03E
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Threading;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using excel = Microsoft.Office.Interop.Excel;
namespace Example_Reading_A_File_From_Excel
{
class Program
{
static void Main(string[] args)
{
excel.Application x1app = new excel.Application();
excel.Workbook x1workbook = x1app.Workbooks.Open(@"D:\saniaertest.xlsx");
excel._Worksheet x1worksheet = x1workbook.Sheets[1];
excel.Range x1range = x1worksheet.UsedRange;
string website;
for(int i = 1; i <= 3; i++)
{
website = x1range.Cells[i][9].value2;
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl(website);
Thread.Sleep(30);
driver.Close();
}
}
}
}
Normally it should open the Excel file and open the Chrome browser and navigate to all the URL that are listed in column 9. But like said before I only get the error:
System.Runtime.InteropServices.COMException HResult=0x800A03E
It says that the workbook can't be found.