-2

The following code is used to open an excel .xls file. However, excel 2016 no longer allows to open the .xls files then a pop-up window appears (see attached image) which should be handled with the last two lines of the code nevertheless the code I wrote did not send me any errors but it just does not do anything.

string FilePath1 = @"MyFilePath";
Process.Start(FilePath1);
Thread.Sleep(2000);
SendKeys.Send("{LEFT}");
SendKeys.Send("{ENTER}");

the code opens the file but when the pop-up window appears it doesn´t press LEFT arrow neither ENTER key. the picture with the pop window is below

enter image description here

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
  • 1
    "excel 2016 no longer allows to open the .xls files" from where did you get this idea? Your file is corrupted, Excel still allows this – Camilo Terevinto Jan 07 '18 at 20:40
  • The file is not corrupt because once that pop-up window appears I click on the button that says "Yes" and load the data and this is really the purpose of my query to click on the button and it is the only thing that I'm interested – user6336440 Jan 07 '18 at 20:47

1 Answers1

0

It is very common thing you see here. The file has extension .xls, but in fact it is xlsx (or, less likely, xlsm, xlsb etc). The extension xls is for old excel format (before 2007), xlsx is for new format (from 2007). These formats are completely different. Excel 2016 still able to open all previous formats, but it tells you that the extension does not match the actual format. So instead of the hack you are using, I suggest you to rename the file to %filename%.xlsx.

Alex Butenko
  • 3,664
  • 3
  • 35
  • 54
  • I'll have to find how to because i am downloading this file from a website that has only to options CSV or XLS so I have to talk either to manger of the app or to the development team, I will let you know about thank you so far – user6336440 Jan 09 '18 at 03:08
  • @user6336440 you cannot rename it from within you program? To me it feels like an easier task than tracking windows and clicking buttons. – Alex Butenko Jan 09 '18 at 03:17