How to detect if workbook is already opened? lazarus / 49-FPSpreadsheet ---------------------------------------------------------------------- krzynio · 2017-10-24 16:47 My application opens existing workbook or creates a new one if it doesn't exist. Next it makes some changes in it, writes them to file and closes the workbook. When workbook is already opened in Excel or OO then I can also open it and make some changes from my Lazarus app. but when I try to write changes I receive an error. The goal is to detect if workbook is already opened and close it before opening it by my application. Can you help how to detect it and close, please. ---------------------------------------------------------------------- wp · 2017-10-24 17:58 Please try this one, it works for Excel (however, probably not for Calc): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  ComObj; // 'd:\workbook.xls' is loaded into Excel.procedure TForm1.Button2Click(Sender: TObject);var  xlApp: OleVariant;begin  try    sWorksheetGrid1.Workbook.WriteToFile('d:\workbook.xlsx', sfOOXML);  except    on E:EFCreateError do begin      if MessageDlg('File is blocked by Excel. Close running Excel instance?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then      begin        xlapp := GetActiveOleObject('Excel.Application');        xlapp.Quit;        ShowMessage('Please save again.');      end;    end;  end;end; ---------------------------------------------------------------------- krzynio · 2017-10-27 05:49 Thank you so much. This is the key: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i on E:EFCreateError do begin