Problems with Word lazarus / 21-General ---------------------------------------------------------------------- w click · 2025-05-13 09:10 I've been developing a program that fires up Word, and does a few clever things like a wordcount to keep a record of progress.  It uses this:- 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 WordApp:=CreateOleObject('Word.Application'); It's been working fine for, I don't know, a year or two, but now it won't close the document (and therefore won't quit). 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       labelinfo.caption:='Saving...'; sourcedoc.save;      labelinfo.caption:='Closing...'; sourcedoc.close;      labelinfo.caption:='Quitting...'; wordapp.quit;      labelinfo.caption:='Done. ';  Instead, Word flashes and requires it to be quit manually without save/don't save/cancel!  (Luckily, the line before this is the sourcedoc.save, which does still work.)  I've tried putting the sourcedoc.close in a try...except, but it still locks up waiting for Word. I suspect a Word issue, but I can't find out what it could be.  Anyone got any ideas, please. ---------------------------------------------------------------------- Thaddy · 2025-05-13 09:17 It may help if you do a call to OleUninitialize(). Otherwise it make still be intact/hold by the OS. ---------------------------------------------------------------------- w click · 2025-05-13 15:00 Quote from: Thaddy on May 13, 2025, 11:17:27 amIt may help if you do a call to OleUninitialize(). Otherwise it make still be intact/hold by the OS. I'm not sure how to do that and can't find anything online.  (And it doesn't explain why it worked for so long and suddenly stopped working.) ---------------------------------------------------------------------- w click · 2025-05-15 11:03 What would happen if I skipped the sourcedoc.close and just wordapp.quit?  Slightly terrified of testing it in case I lose the document, which is important. ---------------------------------------------------------------------- loaded · 2025-05-15 12:17 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,shlobj; procedure TForm1.Button1Click(Sender: TObject);    function GetSpecialFolderPath(CSIDLFolder: Integer): string;    var     FilePath: array [0..MAX_PATH] of char;    begin      SHGetFolderPath(0, CSIDLFolder, 0, 0, FilePath);      Result := FilePath;    end;   var    Word, oPara1 : Variant;    exs:widestring;  begin      exs:=UTF8Decode('Example');      Word := CreateOleObject('Word.Application');      Word.Visible := True;      Word.Documents.Add;      oPara1 := Word.ActiveDocument.Content.Paragraphs.Add;      exs:=UTF8Decode(#13+#13+#13+' Problems with Word ');      oPara1.Range.Text := exs;      oPara1.Range.Font.Name:= 'Times New Roman';      oPara1.Range.Font.Bold := True;      oPara1.Range.Font.Size := 14;      oPara1.Range.ParagraphFormat.Alignment := 1; // Center      oPara1.Range.InsertParagraphAfter();      exs:=UTF8Decode(GetSpecialFolderPath(CSIDL_DESKTOP) + '\Example.docx');      showmessage('Document saved and closed');      Word.ActiveDocument.SaveAs2(exs);      Word.ActiveDocument.close;    Word.quit;  end;