When trying to save a document using the example code below it should save the document on the given location. If the file already exists, it will throw an exception. So far so good. But in a rare case the .SaveAs method blocks, and it will open the MS Word Save As Dialog (if Word is made visible, otherwise it must be activated using the task manager).
The situation only occurs on 1 PC with Windows 10 and Office 2016.
Problem is here, that I don't know when to expect a dialog, the documentation does not say anything about it (https://msdn.microsoft.com/en-us/library/microsoft.office.interop.word._document.saveas.aspx).
What are the conditions of prompting a dialog using SaveAs? In my case I never want to see this dialog. Tried both late and early binding, both same result. Is it a problem that could be fixed by code, or is it somehow a setting in Word?
procedure Example(Sender: TObject);
var
lWord : TWordApplication;
lDoc : TWordDocument;
begin
try
lWord := TWordApplication.Create(Self);
lWord.ConnectKind := ckNewInstance;
lWord.Disconnect;
lWord.Connect;
lWord.Visible := True;
lDoc := TWordDocument.Create(lWord);
lDoc.SaveAs('C:\Temp\test.doc');
except
on e: exception
do
begin
//reResults.Lines.Add(e.Message);
//reResults.Lines.Add(e.StackTrace);
end;
end;
try
lWord.Quit;
finally
end;
end;